我正在使用CakePHP的Auth组件来获取用户登录数据,并希望将users_table与user_details表相关联。该关联有效,如果我手动让用户输出它工作正常,但是当用户登录时是否可以在关联表中加载auth-component?到目前为止,我没有运气试过这个:
$this->loadComponent('Auth', [
'authorize' => ['Controller'],
'authenticate' => [
'Form' => [
'fields' => [
'username' => 'email',
'password' => 'password'
],
'contain' => ['user_details']
]
],
'loginAction' => [
'controller' => 'users',
'action' => 'login'
]
]);
注意"包含" part - 这是我尝试加载相关表但没有运气的地方?
感谢。
答案 0 :(得分:2)
包含已被弃用,有利于' finder'
所以在用户表中定义一个查找器
public function findDetails($query, array $options)
{
return $query
->contain(['UserDetails']);
}
并在AppController中
$this->loadComponent('Auth', [
'authorize' => ['Controller'],
'authenticate' => [
'Form' => [
'fields' => [
'username' => 'email',
'password' => 'password'
],
'finder' => ['details']
]
],
'loginAction' => [
'controller' => 'users',
'action' => 'login'
]
]);
https://book.cakephp.org/3.0/en/controllers/components/authentication.html#customizing-find-query