3

我在 CakePHP 2.3.0-RC1 中使用 ACL

当我更新用户字段(选择营销)时,我收到一个错误:

AclNode::node() - Couldn't find Aro node identified by "Array ( [Aro0.model] => User[Aro0.foreign_key] => 4 ) "

我认为这与拯救用户有关。我在手册中找不到有关如何解决此问题的任何内容。

这是从控制器中截取的方法:

$me = $this->Session->read('Auth.User');
// don't use the session to display, because they might have subscribed/unsubscribed
$user = $this->User->find('first',array('conditions'=>array('User.id'=>$me['id'])));
$optin = ! $user['User']['optin'];
$data  = array(
                'User' => array(
                            'id'    => $me['id'],
                            'optin' => $optin
                        )
            );
if ( $this->User->save($data) ) 
{
    $this->Session->setFlash(__('Subscription status has been amended'));
} 
else 
{
     $this->Session->setFlash(__('The user could not be saved. Please, try again.'));
}
$this->redirect(array('action'=>'account'));

重定向后,我收到 ARO 错误。

4

2 回答 2

1

根据评论,我只是将其写下来作为答案。

我将用户模型设置为请求者,但实际上打算在相关的“组”模型上使用基于角色的身份验证。

我设置了父节点,但忽略了从用户模型中取出 Acts As Requester。

评论这一点很有魅力——我实际上并不需要用户(只是组)的 ARO 对象,它存在只是因为 Cake 教程包含它。

于 2013-06-24T13:02:17.207 回答
0

当前教程(http://book.cakephp.org/2.0/en/tutorials-and-examples/simple-acl-controlled-application/simple-acl-controlled-application.html)说禁用请求者指令

public $actsAs = array('Acl' => array('type' => 'requester', 'enabled' => false));

在用户模型中,以防您打算使用仅限组的 ACL。你必须实现绑定方法:

public function bindNode($user) {
return array('model' => 'Group', 'foreign_key' => $user['User']['group_id']);

}

这对我有用。

于 2014-04-15T10:59:32.013 回答