我正在尝试创建一个链接来编辑用户的信息。id 为 1 的人的 url 将是 users/edit/1
echo $this->Html->link('Edit Info', array(
'controller' => 'users',
'action' => 'edit',
AuthComponent::user('id')
));
URL 正确显示。但是,我试图限制它,以便只有具有该 ID 的用户才能编辑他们的页面。因此,假设用户 4 尝试编辑用户 1 的信息,它将重定向。
这是用户控制器中应该重定向的编辑操作的一部分。
if($id !== AuthComponent::user('id')){
$this->redirect(array('controller'=>'posts','action'=> 'index'));
}
我收到以下错误
Parse error: syntax error, unexpected '=', expecting ')' in /Applications/XAMPP/xamppfiles/htdocs/cake/app/Controller/UsersController.php on line 42
编辑 - 让它工作,感谢您的帮助