【问题标题】:how to get list based on group id如何根据组 id 获取列表
【发布时间】:2012-04-11 01:28:39
【问题描述】:

我有一个 group_id 分配给用户,但在我的用户索引页面上,我想知道属于登录用户所属特定组的用户的方式。 目前它设置为显示所有用户

public function index() {

                            $this->User->recursive = 0;
                            $this->set('users', $this->paginate());
}

我将如何改变它

登录:

public function login() {
     if ($this->request->is('post')){
        if ($this->Auth->login()) {
            $this->redirect($this->Auth->redirect());
        }else {
            $this->Session->setFlash('Your username or password was incorrect.');
        }
    }
}

谢谢

【问题讨论】:

  • 用户是如何登录的?
  • 问题添加登录功能

标签: cakephp cakephp-1.3 cakephp-2.0 cakephp-2.1


【解决方案1】:

要获取当前登录用户的 group_id,请更新 index() 操作以包括:

public function index() {

    // get logged in user info
    $user = $this->Auth->user();
    $group_id = $user['group_id'];

    // add pagination conditions
    $this->paginate = array(
        'conditions' => array('User.group_id' => $group_id)
    );
    $this->User->recursive = 0;
    $this->set('users', $this->paginate('User'));

}

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-23
    • 2017-09-07
    • 2019-11-22
    • 1970-01-01
    相关资源
    最近更新 更多