Codeigniter : calling a method of one controller from other

后端 未结 10 1927
爱一瞬间的悲伤
爱一瞬间的悲伤 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:32

    test.php Controller File :

    Class Test {
     function demo() {
      echo "Hello";
     }
    }
    

    test1.php Controller File :

    Class Test1 {
     function demo2() {
      require('test.php');
      $test = new Test();
      $test->demo();
     }
    }
    

提交回复
热议问题