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, we need to databases.php in the
To fill in the relevant parameters, detailed no longer repeat.
Go directly to the topic:
Mvc:
1, first talk about "M" modelthe model in CI is stored in the Application/models directory.
The naming rule is: Class name _model.php
The file contains only a single 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"the database model and its methods are available. Then we should be extracting the data.
Controllers in CI are stored in the Application/controllers directory
Naming rules: Class name. php
such as:
Prevent illegal access to the IF (! defined (' BasePath ')) exit (' No direct script '); class Nb extends Ci_controller {public fu Nction __construct () {parent::__construct (); Load 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);}} File End Gaze/* End of File nb.php *//* location:./application/controllers/nb.php */
3. Finally talk about "V"the database model and its methods are available. Then we should be extracting the data.
Controllers in CI are stored in the Application/controllers directory
Naming rules: Class name. PHP (and certainly not the class name.) Just with the controller.
? ? ? ? ? The name of the view will be the same.
such as:
PHP endforeach?> </body>
Simple MVC example in getting started with CI framework