To get this movie-related content management system completed, it’s necessary to create all of the view files that are used for the previous “Movies” controller class to display the list of available movies and their corresponding comments, as well as the HTML form that permits the insertion of these comments into the corresponding MySQL table. That being said, here’s the definition of the first view file, called “movie_view.php.” It is utilized by the controller to display the list of movies available for receiving comments. Have a look at it, please: <html> <head> <title><?php echo $title;?></title> </head> <body> <h1><?php echo $title;?></h1> <?php foreach($movies as $movie):?> <h2><?php echo $movie['name'];?></h2> <p><?php echo $movie['description'];?></p> <p><?php echo anchor('movie/comments/'.$movie['id'],'View Comments');?></p> <hr /> <?php endforeach;?> </body> </html> Definitely, the above view file is quite simple to grasp. As you can see, this file will display all of the movies stored in the database. It includes a link that will take users to the comments web page, so they can submit a new comment for each particular movie. Besides, you may want to look at the following screen help, which shows precisely how movies are displayed on screen:
That image was pretty illustrative, right? Now it’s time to include the view file that renders the comments web page, which not surprisingly is called “moviecomment_view.php.” Here it is: <html> <head> <title><?php echo $title;?></title> </head> <body> <h1><?php echo $title;?></h1> <?php foreach($comments as $comment):?> <p><?php echo $comment['author'];?></p> <p><?php echo $comment['text'];?></p> <p><?php echo anchor('movie','Back to movies');?></p> <hr /> <?php endforeach;?> <?php echo form_open('movie/insert_comment');?> <?php echo form_hidden('movie_id',$this->uri->segment(3));?> <p>Enter your comments below:</p> <p><textarea name="text" rows="10"></textarea></p> <p>Author:</p> <p><input type="text" name="author" /></p> <p><input type="submit" value="Submit Comment" /></p> </form> </body> </html> As you can see, the above view file performs a couple of crucial tasks, such as displaying all the comments that have been submitted for a specific movie, and providing a basic HTML form, which lets users add new entries. Of course, you’ll understand much more clearly how this view works, if you look at the following screen capture:
See how easy it is to provide users with an interface that lets them enter comments on a specific movie? I guess you do! Naturally, these two view files should be saved to the Code Igniter /system/application/views/ folders, so that they can be loaded at runtime by the previous controller class. Okay, at this point I have finished building this simple content management system with Code Igniter. If you want to test it, you should type the following URL in your browser’s address field: http://localhost/codeigniter/index.php/movies/ That’s all. If all of the source files created earlier were saved to the correct locations in the web server, then the application should work flawlessly! Finally, feel free to introduce your own modifications to the files, so you can extend your Code Igniter skills to developing database-driven applications. Final thoughts Sad but true, we’ve come to the end of this series. The journey has been long, but hopefully instructive too, since you learned how to use Code Igniter to develop several useful web applications very quickly. So, if you’re looking for a PHP framework that requires minimal setup and an easy learning curve, then Code Igniter might be the piece of software that you really need. See you in the next PHP development tutorial!
blog comments powered by Disqus |
|
|
|
|
|
|
|