用于编辑信息的cakephp身份验证组件

用于编辑信息的cakephp身份验证组件,php,mysql,cakephp,Php,Mysql,Cakephp,我正在尝试创建一个链接来编辑用户的信息。id为1的人员的url将为users/edit/1 echo $this->Html->link('Edit Info', array( 'controller' => 'users', 'action' => 'edit', AuthComponent::user('id') )); URL显示正确。但是,我试图限制它,以便只有具有该id的用户才能编辑他们的页面。所以,假设用户4试图编辑用户1的信息,

我正在尝试创建一个链接来编辑用户的信息。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'));
    }
这是UsersController中编辑操作的一部分,该操作应重定向

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

编辑-让它工作起来,谢谢你的帮助

你可能不想按照你描述的方式来做。如果我是你,我会做一个类似
/profile/edit
的单独路径,然后让它转到
用户
控制器中的特定操作。在该操作中,您将从会话中获取已登录用户的userid,查找该用户,然后向他们显示编辑视图以获取其信息

这将使链接生成看起来像:

echo $this->Html->link('Edit Info', array( 
   'controller' => 'users',  
   'action' => 'edit_profile'
)); 

我不知道如何使用路由,但我用上面的方法让它工作。