The example in this article describes the MVC simple example of getting started with the CI framework. Share to everyone for your reference, specific as follows:
The simplest CI model:
Note: The model needs to use a database
Configuration file in appcation/config.php
Here we want to use the database, need to databases.php in the relevant parameters to fill out, specifically no longer repeat.
Directly into the subject:
Mvc:
1, first talk about "M" model
The model in CI is stored in the Application/models folder.
The naming rule is: Class name _model.php
The file contains only one class:
Such as:
Class Nb_model extends Ci_model {public
function __construct ()
{
//Connection database
$this->load-> Database ();
}
Public function Get () {
//query database
$query = $this->db->get (' users ');
Returns the result of the query as an array return
$query->result_array ();
}
2, the second talk about "C"
With the database model and its methods, we should extract the data.
The controllers in CI are stored in the Application/controllers folder
Naming rules: Class name. php
Such as:
Prevents illegal access to
if (! defined (' BasePath ')) exit (' No Direct script access allowed ');
Class Nb extends Ci_controller {public
function __construct ()
{
parent::__construct ();
Load data Model
$this->load->model (' Nb_model ');
}
The Public Function index ()
{
//obtains data based on the data model
$data [' nb ']= $this->nb_model->get ();
Load view file
$this->load->view (' NB ', $data);
}
Note/* End of File
nb.php
/* Location:./application/controllers/nb.php/*
3, the last talk about "V"
With the database model and its methods, we should extract the data.
The controllers in CI are stored in the Application/controllers folder
Naming rules: Class name. php (or, of course, not a class name, as long as it is consistent with the name of the View argument in the controller)
Such as:
More interested in CodeIgniter related content readers can view the site topics: "CodeIgniter Introductory Course", "CI (CodeIgniter) Framework Advanced Course", "PHP Excellent Development Framework Summary", "thinkphp Introductory Course", " Thinkphp Common Methods Summary, "Zend Framework Introduction Course", "PHP object-oriented Programming Introduction Course", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design based on CodeIgniter framework.