我没有User表。我有一张Customer表。似乎Cakephp Auth无法识别User旁边的任何其他表格。有没有办法绕过这个错误?
如果我尝试使用$this->Auth->User('role')
- 它的效果非常好。但我的所有身份验证凭据都在Customer表下。请帮忙。
我在下面遇到此错误
Fatal error: Call to undefined method AuthComponent::Customer() in
/Applications/MAMP/htdocs/development03/app/app_controller.php on line 56
代码:
function beforeFilter() {
$this->set('admin', $this->_isAdmin());
}
function _isAdmin() {
$admin = FALSE;
if ($this->Auth->Customer('role') == 'admin') {
$admin = TRUE;
}
return $admin;
}
答案 0 :(得分:2)
假设您希望管理员表用户名为电子邮件,密码为字段密码:< / p>
在AppController.php中:
public $components = array('Session',
'Auth' => array('authenticate' => array('Form' => array( 'userModel' => 'Administrator',
'fields' => array(
'username' => 'email',
'password' => 'password'
)
)
),
'authorize' => array('Controller'),
'loginAction' => array('controller' => 'administrators', 'action' => 'login'),
'loginRedirect' => array('controller' => 'Home', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'Home', 'action' => 'index'),
),
);
在AppController.php中也添加:
public function isAuthorized($user){
return true;
}
答案 1 :(得分:0)
您必须使用userModel => ModelName
属性。您的AppController应如下所示:
class AppController extends Controller
{
public $components = array(
'Auth' => array('authenticate' => array('Form' => array('userModel' =>'Customer',
'fields' => array('username' => 'USER_LOGINNAME', 'password' => 'USER_PASSWORD'
)
)
)
)
);
/*...... Your code ............*/
}
This link可能会帮助您解决错误。