我正在开发 cakephp 2.x 。我的问题是我不想使用用户名进行日志记录..我从用户那里获取电子邮件和密码,并从数据库中验证这个电子邮件和密码我的数据库名称用户中有一个表,它有 3 个字段 id、 email和 密码
这是我的代码
模型
<?php
class User extends AppModel {
public $useTable = 'user';
}
?>
应用控制器
class AppController extends Controller {
public $components = array(
'Session',
'Auth'=>array(
'loginRedirect'=>array('controller'=>'users', 'action'=>'admin'),
'logoutRedirect'=>array('controller'=>'users', 'action'=>'admin'),
'authError'=>"You can't access that page",
'authorize'=>array('Controller')
)
);
public function isAuthorized($user) {
}
public function beforeFilter() {
$this->Auth->allow('index');
用户控制器
public function login()
{
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash('Your email/password combination was incorrect');
}
}
}
登录.ctp
<?php
echo $this->form->create();
echo $this->form->input('email');
echo $this->form->input('password');
echo $this->form->end('Authenticate');
?>