If you already went through the preceding articles of this series, then you're already familiar with building simple views. The views that I plan to build now will be really simple to grasp as well. As you’ll surely recall from the controller defined in the previous section, these views must be capable of generating independently the header, main area and footer section of a web page. This is actually very easy to accomplish. Here are the three views that render the web page in question: (‘header_view.php’ file – located at /application/views/ folder) <div id="header"> <h1><?php echo $header;?></h1> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut.</p> </div> (‘content_view.php’ file – located at /application/views/ folder) <div id="content"> <?php foreach($users as $user):?> <p><strong>First Name: </strong><?php echo $user->firstname;?></p> <p><strong>Last Name: </strong><?php echo $user->lastname;?></p> <p><strong>Email: </strong><?php echo $user->email;?></p> <hr /> <?php endforeach;?> </div> (‘footer_view.php’ file – located at /application/views/ folder) <div id="footer"> <h2><?php echo $footer;?></h2> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut.</p> </div> As I said before, the signatures corresponding to the above views are fairly simple to understand. In this case, the “content_view.php” file is possibly the most complex to grasp, but all that it does is iterate over all the rows fetched from the pertinent “users” MySQL table and display the users’ first and last names, as well as their email addresses. Due to the simple structure of the views coded before, I don’t want to spend more time explaining what they do, since that would be pretty pointless. However, as you may have noticed, there’s still one view that remains undefined, called “main_page.php,” which is precisely the one responsible for concatenating the other views. Therefore, the last segment of the tutorial will be focused on creating this layout view, in this manner concluding this instructive journey on handling views with CodeIgniter. Now, if you want to see how this view will be coded, click on the link shown below and read the following section.
blog comments powered by Disqus |
|
|
|
|
|
|
|