Example Analysis of controller inheritance problem of Codeigniter Controller
This article mainly introduces the example analysis of Codeigniter controller controller inheritance problem, the article is very detailed, has a certain reference value, interested friends must read it!
The details are as follows:
Such a situation is often used in projects where each page in the background has to judge the Session to determine whether the user is logged in. For Codeigniter, it is considered that each controller inherits a common controller.
For example: AdminBase is the common controller of the application background, in each application background controller inherits the common AdminBase, but at the same time make sure that the AdminBase also inherits the CI_Controller.
The same is true for HomeBase at the front desk.
The implementation is very simple, as long as you create a new MY_Controller.php under application/core, as follows
(MY_ is configurable, application/config/config.php file and find 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 ();.}.}
Then the controller in application/controllers can be inherited, such as in application/controllers/admin/blog.php
Class Blog extends AdminBase {function _ construct () {parent::__construct ();.}.}. These are all the contents of the article "example Analysis of Codeigniter Controller controller inheritance problems". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!