这是我的服务器 localhost/cakephp/view/login/index.ctp 上的 ctp 文件位置
<div class="wrapper">
<form class="form1" action="posts">
<div class="formtitle">Login to your account</div>
<div class="input">
<div class="inputtext">Username: </div>
<div class="inputcontent">
<input type="text" />
</div>
</div>
<div class="input nobottomborder">
<div class="inputtext">Password: </div>
<div class="inputcontent">
<input type="password" />
<br/><a href="#">Forgot password?</a>
</div>
</div>
<div class="buttons">
<input class="greybutton" type="submit" value="Cancel" />
<input class="orangebutton" type="submit" value="Login" />
</div>
</form>
</div>
用于用户控制器
class LoginController extends AppController {
var $helpers = array('Html', 'Form');
public function index() {
}
function login() {
// if the form was submitted
if(!empty($this->data)) {
// find the user in the database
$dbuser = $this->User->findByUsername($this->data['User']['username']);
// if found and passwords match
if(!empty($dbuser) && ($dbuser['User']['password'] == md5($this->data['User']['password']))) {
// write the username to a session
$this->Session->write('User', $dbuser);
// save the login time
$dbuser['User']['last_login'] = date("Y-m-d H:i:s");
$this->User->save($dbuser);
// redirect the user
$this->Session->setFlash('You have successfully logged in.');
$this->redirect('/posts/');
} else {
$this->set('error', 'Either your username or password is incorrect.');
}
}
}
function logout() {
// delete the user session
$this->Session->delete('User');
// redirect to posts index page
$this->Session->setFlash('You have successfully logged out.');
$this->redirect('/posts/');
}
}
我没有使用默认主题,而是自定义主题在视图/主题/默认上的位置。它正在工作。现在我无法登录身份验证,所以请让我解决它。