codeigniter - 父控制器函数调用取决于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');
}
}
}
任何人都可以帮助或指导我解决问题吗?
太感谢了。
解决方案
推荐阅读
- arrays - 将 x 添加到所有嵌套数组中的每个第二个元素的更快方法
- apache-flink - 流文件接收器:跟踪零件文件何时完成
- flutter - Flutter web 无法使用移动项目中的包
- java - 如何修复“任务 'compileJava' 执行失败”错误。(使用 Intellij Idea 和 Gradle)
- node.js - 使用 Firestore 按多个字段过滤
- java - 在if语句中如何将字符串添加在一起
- c# - 字典方法 Remove 和 Clear (.NET Core) 在枚举期间修改集合。没有抛出异常
- java - 无法签署数据,消息大于模数(但看起来并非如此)
- html - 如何调整字母背景的大小?
- javascript - 注册回调后实现注销