1

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 コードが間違っていますか?

アプリケーションの残りの部分は、すべてのモデル、ビュー、およびコントローラーで問題なく動作します。

4

2 に答える 2

1

Users コントローラから scaffolding を削除して、ベイクしてみてください。

于 2012-10-27T00:02:36.513 に答える
0

「loginRedirect」キーを AuthComponent 設定に入れてみてください:

public $components = array(
    'Session',
    'Auth' => array(
        'logoutRedirect' => array('controller' => 'users', 'action' => 'login'),
        'loginRedirect' => array('controller' => 'users', 'action => 'view'),
        'authError' => 'Error message',
        'authorize' => array(
            'Controller',
            'Actions' => array(
                'actionPath' => 'controllers'
            )
        ),
        'authenticate' => array(
            'Form' => array(
                'fields' => array('username' => 'email')
            )
        )
    )
);

また$this->Auth->login()、自動的に魔法のようにリダイレクトする必要があります。

于 2012-09-26T08:37:40.163 に答える