我得到以下错误:
Strict (2048): Non-static method Controller::referer() should not be called statically,
assuming $this from incompatible context [APP/View/Questions/admin_edit.ctp, line 20]
由此引起:
//in app/View/Questions/admin_edit.ctp
echo $this->Html->link('Cancel', Controller::referer() );
为什么?
您没有。您使用请求对象:
$this->request->referer();
控制器内部不执行其他操作。
小心:referer可能是空的,因此在这种情况下,您可能需要在此处提供回退。
还要注意可选参数$local:
@param boolean $local If true, restrict referring URLs to local server
$referer_url = $this->referer('/', true); // you will get like (without base URL) "/users/profile"
$refererController = Router::parse($referer_url); // this will return $referer_url as array which contains
Array (
[controller] => users
[action] => profile
}
如果有人在使用Router::parse($referer_url)
时遇到任何错误,请在控制器中添加cakepp路由
use Cake'Routing'Router;