The official website has a
video about the creation of a blog. There it is told about application only of representation and the controller, the model falls and remains on independent studying. Next, I will try to tell you how to use the full MVC model on the example of blog entries.
What is Model - View - Controller?

Models (Model) - receives the necessary data.
Views - shows the user data.
Controllers (Controller) - controls the model and view.
')
Suppose a user visits our page. At this point, the Controller calls the Model, which returns the last 10 entries. The data is then transferred from the Controller to the View, which displays the page to the user.
Consider how to implement mvc for example codeigniter.
SqlCREATE TABLE `entries` (
`id` int (11) NOT NULL AUTO_INCREMENT,
`anons` text,
`title` varchar (255) DEFAULT NULL ,
`info` text,
`date_` datetime DEFAULT NULL ,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
ModelFirst, create a Model that selects all posts from the blog.
Our MBlog Model (location /system/application/models/mblog.php) looks like this:
class MBlog extends Model{
function MBlog(){
parent::Model();
}
function getAllEntries(){
$data = array();
$Q = $ this - > db- > get ('entries');
if ($Q- > num_rows() > 0){
foreach ($Q- > result_array() as $row){
$data[] = $row;
}
}
$Q- > free_result();
return $data;
}
}
ControllerSecond, create a Blog Controller (location /system/application/controllers/blog.php). It looks like this:
class Blog extends Controller {
function Blog(){
parent::Controller();
$ this ->load->model( 'MBlog' );
}
function index(){
$data['title'] = “ ”;
$data['entries'] = $ this -> MBlog-> getAllEntries();
$ this -> load-> vars($data);
$ this -> load-> view('template');
}
}
What is going on here?
1. $ data ['title'] will be used as $ title in the Presentation template.
2. Blog entries from the database will be placed in $ data ['entries'] using the MBlog Model.
3. All data in the $ data array is passed to the View.
ViewThird, create the Template view (location /system/application/views/template.php), which displays all entries to the user. It looks like this:
<!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” xml:lang=”en” lang=”en”>
<head >
<meta http-equiv=”content-type” content=”text/html; charset=utf-8” />
<title> <?php echo $title; ?> </title>
</head>
<body>
<?php foreach ($entries as $row){
//
};
?>
</body>
</html>
That's all. For beginners, you can give advice to first create a blog on video, and then modify it.
To have a deeper understanding of how this all works, you can view the
source of one CMS .
Thanks for attention.