【问题标题】:Trying to display a user with the specific role in cakephp 2x试图在 cakephp 2x 中显示具有特定角色的用户
【发布时间】:2017-05-09 04:30:18
【问题描述】:

我正在尝试显示表用户,并且我希望它仅显示具有“主持人”角色的用户。

public function moderators() {

    $this->set('users', $this->paginate());
    $this->User->find('all', array(
    'conditions' => array('User.role' => 'moderator')
)); 

这是我的控制器,它似乎仍在显示我的表格中的所有数据。

【问题讨论】:

  • 我可以看看你的桌子吗?你也没有返回任何东西
  • 这是我的桌子 [1]:i.stack.imgur.com/k1EqF.png
  • 我正在尝试得到这样的 SQL 查询结果 [SELECT * FROM users WHERE role = 'moderator']
  • $this->User->query("select * from users where role = 'moderator';");

标签: php cakephp-2.9


【解决方案1】:

尝试为此使用自定义查询:

$this->User->query("select * from users where role = 'moderator';");

【讨论】:

  • 谢谢你的回复,反正我得到了答案
  • public function moderators() { $moderator = $this->User->find('all', array('conditions' => array('User.role' => 'moderator') )); $this->set('users', $moderator); }
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-10
  • 1970-01-01
  • 2017-11-02
相关资源
最近更新 更多