Home arrow PHP arrow Page 4 - Building a Content Management System with Code Igniter

Completing the CMS with view files - PHP

Welcome to the conclusion of a nine-part series focused on showing you how to build applications with the Code Igniter framework. Designed to allow programmers to create applications rapidly by utilizing the Model-View-Controller pattern, the Code Igniter framework lets you add many capabilities quickly and easily. This article will bring everything we've learned together for the creation of a content management system.

TABLE OF CONTENTS:
  1. Building a Content Management System with Code Igniter
  2. Creating sample MySQL tables and defining a model class
  3. Building a controller class
  4. Completing the CMS with view files
By: Alejandro Gervasio
Rating: starstarstarstarstar / 14
October 08, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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!



 
 
>>> More PHP Articles          >>> More By Alejandro Gervasio
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: