The simplest CI model:
Note: The model needs to use the database
Configuration file in appcation/config.php
Here we need to use the database, the databases.php in the
Fill in the relevant parameters, specifically no longer repeat.
Go directly to the topic:
Mvc:
1, first talk about "M" modelthe 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 () { //Connect to database $this->load-> Database (); } Public function Get () { //query database $query = $this->db->get (' users '); Returns the query result as an array return $query->result_array ();} }
2, second talk about "C"with the database model and its methods, we should be extracting the data.
Controllers in CI are stored in the Application/controllers folder
Naming rules: Class name. php
such as:
Prevent illegal access if (! defined (' BasePath ')) exit (' No Direct script access allowed '); class Nb extends Ci_controller {public fu Nction __construct () {parent::__construct (); Load the data Model $this->load->model (' Nb_model '); } Public Function Index () { ///Data Model $data[' NB ']= $this->nb_model->get ();//Load View file $this->load-> View (' NB ', $data);}} End of File comment/* end of File nb.php *//* location:./application/controllers/nb.php */
3. Finally talk about "V"With the database model and its methods, we should be extracting the data.
Controllers in CI are stored in the Application/controllers folder
Naming rules: Class name. php (and of course not the class name, as long as the controller
Match the name of the view parameter in the
such as:
Simple MVC example in getting started with the CI framework