The first approach that I’m going to explore in this article involves loading views sequentially. To implement this specific method, I’m going to recreate a fictional scenario where an entire web page needs to be generated using the structure mentioned in the introduction. In this particular case, the header and footer sections will be static view files, while the main area will be filled in with dynamic content pulled out from a MySQL database. Based on this scheme, it’s necessary to build the static files that will comprise this sample web page, that is, the header and footer parts. So, here are the two files that perform this task: (definition of ‘header_view.php’ file) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Sample Web Page</title> </head> <body> <div id="container"> <div id="header"> <h1><?php echo $header;?></h1> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p> </div> (definition of ‘footer_view.php’ file) <div id="footer"> <h2><?php echo $footer;?></h2> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p> </div> </div> </body> </html> So far, nothing unexpected, right? As you can see, the structure of the above two view files is pretty easy to follow. In the first case, the “header_view.php” file embeds only a $footer PHP variable into the markup, while the second file does something similar, since the “footer_view.php” view includes another variable called $footer. As I explained before, these views could be considered the static sections of the web page that I plan to generate, even though each of them will contain some data that will be passed along via a still-undefined controller class. Assuming that the latest version of CodeIgniter has already been installed on your testing web server, then the two previous view files should be saved to the /application/views/ folder of CI, so they can be found by its loader class at a later time. Well, at this point I demonstrated how to build the header and footer views of a basic web page, which will be loaded via a sequential method. But, actually I’m getting ahead of myself, since first we need to define the view file that corresponds to the main area of the page. As I mentioned previously, this file will be populated with some database content. Therefore, it’s time to build this additional view file. This process will be discussed in depth in the section to come, so click on the link that appears below and read the following segment.
blog comments powered by Disqus |
|
|
|
|
|
|
|