Codeigniter : calling a method of one controller from other

后端 未结 10 1946
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-05 01:48

I have two controllers a and b.

I would like to call a method of controller a from a method of controller b.

10条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-05 02:30

    very simple in first controllr call

     $this->load->model('MyController');
     $this->MyController->test();
    

    place file MyController.php to /model patch

    MyController.php should be contain

    class MyController extends CI_Model {
    
        function __construct() {
            parent::__construct();
        }
        function test()
        {
            echo 'OK';
        }
    }
    

提交回复
热议问题