As I stated in the previous section, to finish developing this blog application with Code Igniter, it’s necessary to create another view file. This file will be charged with printing, on screen, all of the comments that have been submitted for each blog entry.
To demonstrate how this file really functions, I’m going to assume that a few trivial comments have already been stored in the pertinent “blogs_comments” MySQL table. However, in a typical situation, users should be able to post their comments via an HTML form. Since this topic will be covered in depth in the next tutorial of the series, for now I’ll keep the blog application working this way.
Now that I have explained the functionality of the “blogs_comment_view.php” file, please take some time to study its signature, which looks like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php echo $title;?></title>
<h1><?php echo $title;?></h1>
<?php foreach($result->result_array() as $comment):?>
<p><strong>Author: </strong><?php echo $comment['author'];?></p>
<p><?php echo $comment['text'];?></p>
<p><?php echo anchor('blogger/blogs/','<< Back to blog');?></p>
As illustrated above, the previous view file is responsible for performing a few interesting tasks, such as displaying all the comments that have been made on a particular entry, and including a link that takes users to the blogger’s main page.
In addition, you can see that each comment includes the author that submitted it and the corresponding text as well. Nonetheless, as I stated before, this operation should be performed through a typical web form; the details of this topic will be discussed in the next article in this tutorial series.
For now, the only step that remains undone is to save the previous view file to the Code Igniter /system/application/views/ folder, so go ahead and do that. Then, if you test the blog application and click on any of the links that points to the comments web page, you should get an output similar to this:
Naturally, the above image exemplifies a situation where some blog entries have already received comments, so you can see more clearly how the blogger works.
Okay, at this point, the initial functionality of this blog application has been slightly extended; it's now capable of displaying not only all of the existing blog entries, but the comments that have been posted on each of them. As usual with many of my articles on PHP development, feel free to tweak all the code samples developed in this tutorial to expand your existing Code Igniter skills.
In this third part of the series, I explained how to improve the functionality of this blogger by providing it with the capacity for displaying a bunch of comments that correspond to each blog entry. However, as I explained earlier, for entering new comments it is necessary to code a typical HTML form.
Therefore, in the following article I’ll discuss how to achieve this with Code Igniter. Now that you know what will be covered in the next tutorial, you don’t have any excuses to miss it!
blog comments powered by Disqus