CodeIgniter call same function for all controllers

别来无恙 提交于 2019-12-06 01:38:50

You can create MY_Controller class in application/core

Class MY_Controller Extends CI_Controller{

    public function __construct(){
        parent::__construct();
    }

    public function common(){
        // code here
    }
}

Now extend every class with MY_Controller and the function will be available for each class

Class Test Extends MY_Controller{

    public function __construct(){
        parent::__construct();
    }
}

When in the url you call

http://localhost/app/test/common

This will work.

create a model class and create that all function after that extend that model all model classes .you can use one function different controller.other wise you can use Cms helper.this is the best way call a common function in different controller.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!