【问题标题】:create Blog with CakePhp but issue with role of users?使用 CakePhp 创建博客但用户角色有问题?
【发布时间】:2015-05-17 02:44:44
【问题描述】:

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

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.'));
        }
    }
}

【问题讨论】:

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


    【解决方案1】:

    这不会将“角色”设置为 1。

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

    你需要这个:

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

    编辑:

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

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

    【讨论】:

    • 谢谢,但我还有一个问题,我设置了可见性。 1 为可见,2 为隐藏,但管理员也没有看到主题还为管理员设置了可见的条件 { }
    猜你喜欢
    • 2018-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-13
    相关资源
    最近更新 更多