CodeIgniter Study Note III: Extended CI Controller, model

Source: Internet
Author: User
Tags codeigniter
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.