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 Users Public 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 function index () { //load Model$this -load model (' User_model '); $usermodel User_model , GetAll, $this . // aliases $this -load model (' User_model ', ' User '); $usermodel getAll, $this, user- Var_dump ($usermodel);}
The model is mainly used to standardize the project structure.
The above describes the CodeIgniter study note three: Extended CI controller, model, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.