douhui5529
2012-06-27 12:38 阅读 116
已采纳

如何从另一个控制器加载控制器的方法?

I have the following controller:

class Tests extends CI_Controller {

        public function update_record_test()
        {
              //some methods
        }
}

?>

But I need to execute Method1 method from Controller1 controller. How can I do it?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    doulang5323 doulang5323 2012-06-27 12:40

    There's not much information here, or I may be missing something, but what's wrong with

    class Tests extends CI_Controller {
    
        public function update_record_test()
        {
              $controller1 = new Controller1();
              $controller1->Method1();
        }
    }
    
    点赞 评论 复制链接分享
  • duanqianpu6499 duanqianpu6499 2012-06-27 12:41

    If you mean you want to execute a function of your main class CI_CONTROLLER, try this.

     parent::Method1();
    

    Check the http://php.net/manual/en/keyword.extends.php for more examples

    点赞 评论 复制链接分享

相关推荐