Codeigniter controller inheritance problem instance analysis

Source: Internet
Author: User
Tags codeigniter
This article mainly introduces the controller inheritance problem of Codeigniter, and analyzes the implementation and usage of controller inheritance in CodeIgniter in the form of a simple example, for more information, see the example in this article. We will share this with you for your reference. The details are as follows:

This is often used in projects. in the background, each page must determine the Session to determine whether the user is logged in. in Codeigniter, each controller inherits a public controller.

For example, AdminBase is the public controller of the application background. in each application background controller, it inherits the public AdminBase, but it must also be ensured that AdminBase inherits the CI_Controller.

The same applies to HomeBase at the front end.

The specific implementation is very simple. you only need to create MY_Controller.php under application/core, as shown below:
(MY _ is configurable. in the application/config. php file, locate this item: $ config ['subclass _ prefix'] = 'My _';)

class MY_Controller extends CI_Controller{function __construct(){parent::__construct();}}class AdminBase extends MY_Controller{function __construct(){parent::__construct();......}......}class HomeBase extends MY_Controller{function __construct(){parent::__construct();......}......}

The controllers in application/controllers can be inherited, such as in application/controllers/admin/blog. php.

class Blog extends AdminBase{function __construct(){parent::__construct();......}......}

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.