我需要在 CakePHP 3.4 中使用自定义查找查询对用户进行身份验证。我为此遵循了烹饪书,但在我的findAuth
方法中$option
返回 empty array
。我不知道代码中的错误是什么。
public function initialize()
{
parent::initialize();
$this->loadComponent('RequestHandler');
$this->loadComponent('Auth', [
'authenticate' => [
'Form' => [
'finder' => 'auth',
'fields' => ['username' => 'username', 'password' => 'password']
]
],
]);
}
用户表.php
public function findAuth(\Cake\ORM\Query $query, array $options)
{
debug($options);
$query->select(['sno', 'username', 'password','contact'])
->where(['Users.username' => $options['username']]);
return $query;
}
登录.ctp
<?php
echo $this->Form->create();
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->submit();
echo $this->Form->end();
?>