duanqun9740 2013-08-13 12:20
浏览 38
已采纳

CakePHP ACL插入NULL

I have the following:

User

Groups

in the groups table i have three groups:

Employee, Client and testGroup

Now when i try to add new users i use the following form:

enter image description here

As you can see from this form the Add user controller registers all of my groups!

However when i add the new user my user is inserted into the Users table but with group id null:

enter image description here

And in my Aros the parent_id is null aswell.

Now this is my User model:

    class User extends AppModel {
    public $belongsTo = array('Group');
    public $actsAs = array('Acl' => array('type' => 'requester'));

    function parentNode(){
        if (!$this->id) {
            return null;
        }
        $data = $this->read();
        if (!$data['User']['group_id']){
            return null;
        } else {
            return array('model' => 'Group', 'foreign_key' => $data['User']['group_id']);
        }
    }

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

    public function beforeSave($options = array()) {
        if (isset($this->data[$this->alias]['password'])) {
            $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
        }
        return true;
    }
}

And this is my User controller:

App::uses('Security', 'Utility');

class UsersController extends AppController {

public $components = array(
    'Cookie',
    'BloglicHelper',
    'Session',
    'HasOffers',
    'RequestHandler'
);

function beforeFilter() {
    $this->Auth->allow('add', 'index', 'login','logout');
}

function add() {
    if (!empty($this->data)) {
        $this->User->create();
        if ($this->User->saveAll($this->data)) {
            $this->Session->setFlash(__('The User has been saved', true));
            $this->redirect(array('action'=>'index'));
        } else {
            $this->Session->setFlash(__('The User could not be saved. Please, try again.', true));
        }
    }
    $groups = $this->User->Group->find('list');
    $this->set(compact('groups'));
}

Can anyone tell me what im doing wrong

Update When i try to print out the data from the form i get the following:

Array ( [User] => Array ( [username] => root [password] => admin ) [group_id] => 1 ) 

Which is correct.

  • 写回答

1条回答 默认 最新

  • duanbaque4230 2013-08-13 20:54
    关注

    Try to see your view, probably your form incorrectly. when you do a debug $ this-> data should be answered in this way:

    Array ( 
          [User] => Array 
                 ( 
                   [username] => root 
                   [password] => admin 
                   [group_id] => 1 
                 ) 
           )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!