First, the controller in the extended CI
It is sometimes necessary to unify the controllers in the CI, such as login and authorization verification, which can be achieved by extending the CI controller.
The extended CI controller only needs to build a My_controller class in the Application/core folder that inherits from the Ci_controller class, and then implement the logic you need in this class.
There are two things you need to explain about the above sentence:
1, why in the Application/core folder: Because the base class Ci_controller is in the System/core folder, which needs to correspond with the system.
2, why the extended controller prefix is my_, can be replaced by other: This prefix is defined in the application/config/config.php:
$config [' subclass_prefix '] = ' my_ ';
Just need these two to correspond on can.
Second, the model
Example application/models/user_model.php:
<? PHP /* * * * * User_model* /classextends ci_model{ // return all userspublic function getAll () { $res $this , DB, Get (' Test '); return $res , result (); } }
Note the point:
1. File name All lowercase
2, the first letter of the class name capital
3. Properties in the Super object can be used in the model
4, it is recommended to use _model as a suffix to prevent conflicts with other class names
Examples of Use:
Public functionindex () {//Load Model $this-Load model (' User_model '); $usermodel=$thisUser_model,GetAll (); //aliases $this-Load model (' User_model ', ' User '); $usermodel=$thisUser-GetAll (); Var_dump($usermodel);}
The model is mainly used to standardize the project structure.
CodeIgniter Study Note III: Extended CI Controller, model