我是新蛋糕php 2.9,我在登录功能中有一个小问题我的代码在视图和登录控制器如下
public function login() {
if($this->request->is('post')) {
if($this->Auth->login()) {
return $this->redirect($this->Auth->redirectUrl());
} else {
$this->Session->setFlash('Invalid Username or Password!');
}
}
}
我的视图/用户/登录文件代码是
<?php
echo $this->form->create('User');
echo $this->form->input('user_name');
echo $this->form->input('password');
echo $this->form->end('login');
?>
数据库名称是用户,模型类名称用户, 数据库列名称=用户名和密码
谢谢
答案 0 :(得分:0)
请检查您的AppController.php是否有适当的设置。
// app/Controller/AppController.php
public $components = array(
'Auth' => array(
'loginAction' => array(
'controller' => 'users',
'action' => 'login',
),
'authError' => 'Did you really think you are allowed to see that?',
'authenticate' => array(
'Form' => array(
'fields' => array(
'username' => 'user_name', //Default is 'username' in the userModel
'password' => 'password' //Default is 'password' in the userModel
)
)
)
)
);
这里最重要的是
'authenticate' => array(
'Form' => array(
'fields' => array(
'username' => 'user_name', // important!!!!
'password' => 'password'
)
)
)