php - __call 方法在尝试调用 yii Controller 中不存在的函数时未执行?

标签 php yii

<?php
class ReportsController extends CController
{
    public function __call($name,$argument)
    {
        echo "test";
    }

}
?>

这是我的 Yii Controller 类,当调用 index.php?r=reports/test URL 时,它必须调用 __call 方法,因为测试方法不存在但它给出错误 The system is unable to find the requested action test 错误。

最佳答案

在你的 Controller 中实现missingAction方法,

如@xdazz 所述,它检查方法是否存在,如果不存在,则调用 missingAction 方法。

//This method is invoked when the controller cannot find the requested action.

public function missingAction($actionID)
{
    // Your code here
}

关于php - __call 方法在尝试调用 yii Controller 中不存在的函数时未执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12852724/

相关文章:

php - 一个 5 位数的 mt_rand() 数字有多独特?

javascript - 从 javascript 向 Yii Controller 发送数据

php - 使用 cpanel (godaddy) 在共享服务器上托管 Yii2 应用程序的步骤

php - 在不重新加载页面的情况下从 MYSQL 表更新值?

php - 如何检查用户是否关注用户列表中的另一个用户?

php - 为 PostgreSQL 中的 WHERE IN 子句绑定(bind)多行和多列

php - 更改数组中的值

php - 自定义搜索需要根据选择的名字显示名字搜索结果

php - 如何在 Controller 中检查验证码?

php - 在 Yii2 中输出关系数据