CakePHP检查参考

CakePHP检查参考,php,cakephp,Php,Cakephp,我有以下代码: function success() { if(!$this->referer(array('controller'=>'contact','action'=>'index'))) { $this->redirect(array('controller'=>'contact','action'=>'index')); } } 我试图检查用户是否通过索引操作

我有以下代码:

function success()
    {
        if(!$this->referer(array('controller'=>'contact','action'=>'index')))
        {
            $this->redirect(array('controller'=>'contact','action'=>'index'));
        }
    }
我试图检查用户是否通过索引操作访问了成功页面,如果没有,则将其发送回index方法,这样,如果用户之前没有提交有关索引操作的某些数据,则无法查看成功页面

但是,它不起作用,因为即使用户没有首先访问索引页面,他们仍然可以访问成功页面


有人能帮忙吗?谢谢

我想那样不行。您现在只需使用该代码设置默认的referer。尝试以下方法:

if($this->referer() != Router::url(array('controller'=>'contact','action'=>'index')))
编辑:更正代码

尝试在Router::url的末尾添加true,获取完整url的函数:

function success()
{
    if($this->referer() != Router::url(array('controller'=>'contact','action'=>'index')))
    {
        $this->redirect(array('controller'=>'contact','action'=>'index'));
    }
}
if($this->referer() != Router::url(array('controller'=>'contact','action'=>'index'),true))

给出以下错误(第41行是您提供的行)
注意(8):未定义属性:ContactController::$Html[APP/controllers/contact_controller.php,第41行]致命错误:调用成员函数url()在第41行的/nfs/c03/h01/mnt/52704/domains/driz.co.uk/html/app/controllers/contact_controller.php中的非对象上
是否使用了html帮助程序<代码>var$helpers=array('Html')