0

authErrorURLをカスタマイズする方法CakePHPですか?Auth配置したコンポーネントを調べるとAppController、リダイレクトアクションがloginRedirectありlogoutRedirectますが、次のような設定が可能かどうかわかりませんauthErrorRedirect

<?php
class AppController extends Controller {

    public $components = array(
        'Session',
        'Auth' => array(
            'loginRedirect' => array('controller' => 'users', 'action' => 'index'),
            'logoutRedirect' => array('controller' => 'users', 'action' => 'index'),
            'authError' => 'You don\'t have the right to go there.',
            // something like this
            'authErrorRedirect' => array('controller' => 'users', 'action' => 'login'),
            'authorize' => array(
                'Controller',
                'Actions' => array(
                    'actionPath' => 'controllers'
                )
            ),
            'authenticate' => array(
                'Form' => array(
                    'fields' => array('username' => 'email')
                )
            )
        ),
        'Acl'
    );

authErrorリダイレクトアクションを設定できますか?

4

1 に答える 1

0

いいえ。SimpleAuthenticationandAuthorizationアプリケーションの例@CakePHPCookbook v2.xのドキュメントに従う場合は、「無効なユーザー名またはパスワード...」でログインが失敗するログインアクションにリダイレクトする必要があります。これらは、次の例のlogin2で、別のアクションにリダイレクトする場合にのみ意味があります。

public function login() {
    if ($this->request->is('post')) {
        if ($this->Auth->login()) {
            $this->redirect($this->Auth->redirect());
        } else {
            $this->Session->setFlash(__('Invalid username or password, try again'));
            $this->redirect(array('controller' => 'users', 'action' => 'login2'));
        }
    }
}
于 2012-09-07T10:02:23.430 に答える