icon for lab

CT310

Recitation - 8

In this recitation, we will:


Quiz 1: HTML is on this Thursday!

Benefits:

  • Less redundancy
  • Only worry about body content

This simple template example should help you start your FuelPHP web app!

  1. With Fuel installed, find your 'fuel/app/classes/controller' directory, inside you'll find a file: welcome.php
    • Make a copy of this file and call it home.php
    • Delete all the comments on top (keep opening php tag) and methods except 'action_index'
    • Clear all the contents of 'action_index' and add the following:
      • die('home index');
    • Finally, change the name of the class to 'Controller_Home'
    • Navigate to 'http://www.cs.colostate.edu:4444/~EID/ct310/index/home'. You should see the text 'home index'.
    • Inside home.php create another method called 'action_other' and add a 'die' statement with the text 'home other'
    • Navigate to you site but this time use '/index/home/other'
  2. Cool, right? Now let's use a View instead of die statements
    • Create a directory called 'home' in 'fuel/app/views/' and then a file inside that directory called index.php
    • Add anything to the page to identitfy it (the strings from before are probably best)
    • Back in your controller home.php, clear the die statement and add this:
      • return Response::forge(View::forge('home/index'));
    • Check your site and see if you can see your message
  3. Awesome! But what about the template?
    • Each page will need a header or footer with similar links. Go back to your controller home.php and extend it to 'Controller_Template'
    • Clear the 'action_index' and add this:
      • $data = array();
      • $this->template->title = 'Home Page';
      • $this->template->content = View::forge('home/index', $data);
    • Now go back to your views directory and create a file called template.php(outside of the home folder). Add the following:
      • <h1>MAIN TEMPLATE</h1>
      • <?php echo $content; ?>
    • Navigate to your site and check if the template loads
  4. Do the same for the 'action_other' page to load different content into the template!