CakePHP で AuthComponent のデフォルトの動作を使用しようとしていますが$this->Auth->redirect()
、login
アクションでメソッドを使用しようとすると、奇妙な動作が発生します。
ログインしたユーザーを、要求された URL記事への CakePHP ログインview
リダイレクトのように、以前にリダイレクトされた場所にリダイレクトしたいと思います。どこが間違っているのか理解せずに認証も読みました。CakePHP 1.3
これが私のコードです:
AppController
public $components = array(
'Session',
'Auth' => array(
'logoutRedirect' => array('controller' => 'users', 'action' => 'login'),
'authError' => 'Error message',
'authorize' => array(
'Controller',
'Actions' => array(
'actionPath' => 'controllers'
)
),
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'email')
)
)
)
);
ユーザーコントローラー
public function login () {
if ($this->request->is ('post')){
if ($this->Auth->login()) {
$auth_user = $this->Auth->user();
$this->User->id = $auth_user['id'];
$this->User->saveField('last_login', date('Y-m-d H:i:s'));
$this->Session->write('flash_element','done');
$this->Session->setFlash('Welcome back <b>'.$auth_user['username'].'</b>!');
$this->redirect ($this->Auth->redirect());
} else {
$this->set('flash_element','warning');
$this->Session->setFlash('Wrong login');
}
}
}
この設定は、私が正確に文字列を取得したhttp://site.com/users/img/favicon.png
場合にリダイレクトします。debug
$this->Auth->redirect()
/users/img/favicon.png
default.ctp
レイアウト ファイルの行にコメントを付けようとしましたが、その後にコメントを付けようとしましたがeverything works perfect
、なぜですか?
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title><?php echo $title_for_layout; ?></title>
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<?php
echo $this->Html->css('style.css');
//echo $this->Html->meta('icon','img/favicon.png');
...
この行が私AuthComponent
の を壊す理由がわかりませんでした。favicon コードが間違っていますか?
アプリケーションの残りの部分は、すべてのモデル、ビュー、およびコントローラーで問題なく動作します。