因为我使用Cakephp,所以我使用Mysql和Cakephp约定(带有用户名和密码字段的用户表)。
出于某种原因,我必须使用带有 loginutil
而不是用户名和 mdputil
而不是密码的 Postgres 数据库。我使用一个名为 Utilisateur
的表。
这是我放入AppController的代码.php用于身份验证组件:
$this->loadComponent('Auth', [
'authenticate' => [
'Form' => [
'fields' => [
'username' => 'loginutil',
'password' => 'mdputil'
],
'userModel' => 'Utilisateur'
]
],
'loginAction' => [
'controller' => 'Utilisateur',
'action' => 'login'
]
]);
在login.ctp中,我有两个输入:
$this->Form->input('loginutil');
$this->Form->input('mdputil');
我的 UtilisateurController.php 中的登录方法是默认的登录方法,具有$user = $this->Auth->identify();
但是当我尝试登录我时,$user
是错误的。找不到用户。
我试着把这个:
$this->Auth->config('authenticate', [
AuthComponent::ALL => ['userModel' => 'Utilisateur'],
'Basic',
'Form'
]);
但这并不好。
我是否在代码中的某个地方犯了错误,或者我没有正确阅读文档?
感谢您的帮助。
如果您的数据库表名为 utilisateur,请在 model/Table/UtilisateursTable .php中指定此行
namespace App'Model'Table;
use Cake'ORM'Table;
class UtilisateurTable extends Table {
public function initialize(array $config) {
$this->table('utilisateur'); // this line is important, otherwise, it assumes that your database table is utilisateurs
}
}
尝试在模型中使用public $useTable = 'Utilisateur';