Advertisement
Guest User

viewStory.php

a guest
Feb 28th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.16 KB | None | 0 0
  1. <!--Previously we were retrieving an array of stories, but here we're only getting one.-->
  2.  
  3. <?php
  4. require_once 'classes/Connection.php';
  5. require_once 'classes/Story.php';
  6. require_once 'classes/Util.php';
  7.  
  8.  
  9. try{
  10.  
  11. /*The $_GET method checks the URL for any 'id' parameters.*/
  12.  var_dump($_GET['id']);
  13.    
  14. $story = Story::find($_GET['id']);
  15.    
  16.     if($story === false)
  17.     {
  18.         throw new Exception("Story not found");
  19.     }
  20.     else{
  21.         /*These are the same as we have in our test.php foreach loop, just this time we only want to see them once.*/
  22.         $category = Util::selectById('categories',$story->category_id);
  23.         $author = Util::selectById('authors',$story->author_id);
  24.     }
  25. }
  26.  
  27.  
  28.  
  29. catch(Exception $e){
  30.  
  31.     die("Exception: " . $e->getMessage());
  32.    
  33.    
  34. }
  35.  
  36.  
  37.  
  38. ?>
  39.  
  40.  
  41. <!DOCTYPE html>
  42. <html lang="en">
  43.  
  44.  
  45.  
  46.  
  47. <head>
  48.  
  49.  
  50.  
  51.     <title>News Site</title>
  52.  
  53.     <link rel="stylesheet" type="text/css" href="css/grid.css">
  54.     <link rel="stylesheet" type="text/css" href="css/style.css">
  55. </head>
  56.  
  57. <body>
  58.  
  59.     <div>
  60.  
  61.         <label>Headline: </label>
  62.         <? = $story->headline ?>
  63.  
  64.     </div>
  65.  
  66. </body>
  67.  
  68. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement