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();......}......}