Before I proceed to modify the signature of the controller class that I built in the previous article, I’d like to list it in its current state, along with the corresponding view file. This will remind you of how these two source files looked before we make the appropriate changes to their respective signatures. That being said, here are the definitions for the files in question: // definition for 'blogger.php' file (located at /system/application/controllers/ folder) class Blogger extends Controller{ function Blogger(){ // load controller parent parent::Controller(); // load database class and connect to MySQL $this->load->database(); // load pagination library $this->load->library('pagination'); // load helper $this->load->helper('url'); } // display all blog entries function blogs(){ $data['title']='Blog Entries Listing'; $data['result']=$this->db->get('blogs',3,$this->uri->segment(3)); // set pagination parameters $config['base_url']='http://127.0.0.1/codeigniter/index.php/blogger/blogs/'; $config['total_rows']=$this->db->count_all('blogs'); $config['per_page']='3'; $config['full_tag_open']='<div id="paginglinks">'; $config['full_tag_close']='</div>'; $this->pagination->initialize($config); // create pagination links $data['links']=$this->pagination->create_links(); // load 'blogger_view' view $this->load->view('blogs_view',$data); } } // definition for 'blogs_view.php' file (located at /system/application/views/ folder) <!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><?php echo $title;?></title> </head> <body> <h1><?php echo $title;?></h1> <?php foreach($result->result_array() as $blog):?> <h2><?php echo $blog['title'];?></h2> <p><?php echo $blog['text'];?></p> <p><?php echo anchor('blogger/comments/'.$blog['id'],'View Blog Comments >>');?></p> <?php endforeach;?> <?php echo $links;?> </body> </html> As you can see, the above “Blogger” controller class implements a method called “blogs(),” which not only retrieves all the entries from the pertinent “blogs” MySQL table, but splits this data into several chunks. In this way it implements an effective pagination mechanism. Finally, the controller loads the view file shown above, which is used to display all of the blog entries on screen, along with the corresponding pagination links. Okay, at this point you hopefully recalled how the two previous files do their business, right? Therefore, it’s time to see how to modify the signature of the controller class, and provide it with the capacity for displaying all of the comments submitted by users. The full details of this process will be discussed in the following section. Thus, click on the link below and keep reading, please.
blog comments powered by Disqus |
|
|
|
|
|
|
|