CodeIgniter 2: How to extend CI_Controller multiple times?

前端 未结 5 1070
野性不改
野性不改 2020-12-08 10:38

I have successfully extended the CI_Controller class by creating a MY_Controller.php which I have placed in the application/core directory.

core/My_Controlle

5条回答
  •  攒了一身酷
    2020-12-08 11:20

    You just put both in the same file, I have a project that is exactly the same as this.

    We just have both the admin and normal extended controller in the MY_Controller.php file, works fine.

    The main reason for the MY_Controller or other extended files is so that CodeIgniter auto initiates them when you load the base file (whether library, helper, etc.), you can have many classes in these files.

    Edit:

    You don't even need to call them MY_Admin_Controller or MY_Controller, we have Admin_Controller and User_Controller and Ajax_Controller in the MY_Controller File

提交回复
热议问题