首页 > 解决方案 > 父控制器函数调用取决于http方法?

问题描述

我有一个扩展 CI_Controller 的控制器基类,然后还有一些扩展我的控制器基类的其他类。

我想在 http post 方法案例中的最低层次控制器中添加一些新功能,但是当我提交表单时,执行不会通过子 post 方法条件。

就像 post 方法调用将转到以前的控制器类而不通过子函数。

我已经尝试了一个只有 http get case 的函数并且可以工作。

更新:对不起我的错误。

我发现了问题,我在父 post 方法中有一个重定向,这就是执行不通过子 post 方法条件的原因,¿ 如果存在覆盖父函数的函数,是否有任何方法可以在子函数中动态重定向如果该方法没有被任何子类覆盖,或者在父类中重定向?

class MY_Controller extends CI_Controller {

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

   public function create() {
       if ($this->input->server('REQUEST_METHOD') == 'POST') {
           //do things...

           redirect();
       }
       else
       {
            //do other things...
       }
}

class One_Controller extends MY_Controller {

  public function __construct() {

    parent::__construct();
  }

  public function create() {

    parent::create();

    if ($this->input->server('REQUEST_METHOD') == 'POST') {

      var_dump('POST');
      //do more things...
      redirect(); // here and not in the parent
    }
    else {
      var_dump('GET');
    }
  }
}

任何人都可以帮助或指导我解决问题吗?

太感谢了。

标签: codeigniter

解决方案


推荐阅读