使用CakePhp创建博客,但问题是用户的角色?

时间:2015-03-14 17:51:33

标签: php cakephp model-view-controller blogs role

当我向新用户注册时,它总是将空值放入数据库中。 也是可见/隐藏给管理员和用户的主题。请解决它 这是代码:

public function add() {
    if ($this->request->is('post')) {
        $this->User->create();
        $this->request->data['User']['password'] = AuthComponent::password($this->request->data['User']['password']);
        $this->request->data['User']['role'] === '1';
        if ($this->User->save($this->request->data)) {
            $this->Session->setFlash(__('The user has been saved.'));
            return $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('The user could not be saved. Please, try again.'));
        }
    }
}

1 个答案:

答案 0 :(得分:0)

这不会设置'角色'到1。

$this->request->data['User']['role'] === '1';

你需要这个:

$this->request->data['User']['role'] = 1;

编辑:

$ this-> Auth->用户('角色')应该等于您的管理员角色。我希望你的编码是1。

<?php if($this->Auth->user('role') == 1  || $topic['Topic']['visible'] == 1): ?>
  /* Your Topic */
<?php endif; ?>