1

指定したログイン ページにリダイレクトする方法を示す記事を読みました。ただし、私が望むのは、ユーザーがフロントエンドに来た場合、フロントエンドのログインページにリダイレクトする必要があり、同様のことがバックエンドに適用されることです。出来ますか?

4

3 に答える 3

3

構成ファイル ( main.php) で、ログイン URL を設定してください。

// user
    'user'=>array(
    // enable cookie-based authentication
    'allowAutoLogin'=>true,
    // set the url where user must be redirected if authentication needed
    // use null to force 403 HTTP error 
    'loginUrl'=>'/site/login',
    // set here the name of a class
    // that extends CWebUser and it is stored in
    // protected/components/<classname>
    // see: http://www.yiiframework.com/doc/cookbook/60/
    'class' => 'WebUser',
    ),

この URL を参照してください: http://www.yiiframework.com/wiki/59/

次に、Home Controller( SiteController.php) にこのコードを追加して、Index Home が認証されたユーザーのみがアクセスできるようにします。

public function filters()
{
    return array(
        'accessControl', // perform access control for CRUD operations
    );
}

/**
 * Specifies the access control rules.
 * This method is used by the 'accessControl' filter.
 * @return array access control rules
 */
public function accessRules()
{
    return array(
        array('allow', // allow authenticated user to perform 'create' and 'update' actions
            'actions'=>array('index', 'action1', 'action2', 'anotherAction'),
            'users'=>array('@'),
        ),
        array('deny',  // deny all users
            'users'=>array('*'),
        ),
    );
}

この URL を参照してください: http://www.yiiframework.com/doc/guide/1.1/en/topics.auth

于 2012-06-04T04:29:51.867 に答える
0
'components' => [
    ...
    'user' => [
        'identityClass' => 'app\models\User',
        'loginUrl' => [ 'YourController\YourLogin' ],
    ],
]

main.php で。

loginUrl は配列で宣言する必要があります

于 2015-02-10T08:25:35.587 に答える
0

最も簡単な方法は、必要に応じてユーザー値を決定することです

Yii::app()->getUser()->setState('LoginReturnUrl', 'frontend/login');

また

Yii::app()->getUser()->setState('LoginReturnUrl', 'backend/login');

コントローラー内でリダイレクトします。

$this->redirect(Yii::app()->createUrl(Yii::app()->getUser()->getState('LoginReturnUrl')));
于 2012-06-03T17:39:28.390 に答える