我試圖將一個條件傳遞給我的UserController,以查看某些用戶的角色與我嘗試訪問的頁面相匹配的用戶。CakePHP用戶角色檢索
例如:
/管理=> User.admin
/學生=> User.student
我能夠檢索使用查找所有已註冊的學生名單(」所有')函數,但是當我嘗試通過設置條件來篩選角色時,我收到一個引用我的代碼和我試圖檢索的角色的錯誤。
這裏是我的功能在我的控制器:
public function index($role="admin") {
//debug($role);
$this->User->recursive = 0;
$this->request->data('users', $this->User->find('all',
array('conditions' => 'User.role')));
$this->set('users', $this->paginate());
}
任何提示嗎?
試試這個公共功能指數($角色=」管理員「){ // debug($ role); $ this-> User-> recursive = 0; ('users',$ this-> user-> find('all', array('conditions'=> array('User.role'=>'admin'))) ); $ this-> set('users',$ this-> paginate()); } –