Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 选择使用Yii重定向到2 loginUrl?_Php_Login_Yii - Fatal编程技术网

Php 选择使用Yii重定向到2 loginUrl?

Php 选择使用Yii重定向到2 loginUrl?,php,login,yii,Php,Login,Yii,我读过一篇文章,。然而,我想要的是,如果用户来到前端,他们应该被重定向到前端登录页面,类似的应用到后端。可能吗?最简单的方法应该是根据需要确定用户值 Yii::app()->getUser()->setState('LoginReturnUrl', 'frontend/login'); 或 并在控制器内重定向: $this->redirect(Yii::app()->createUrl(Yii::app()->getUser()->getState('Log

我读过一篇文章,。然而,我想要的是,如果用户来到前端,他们应该被重定向到前端登录页面,类似的应用到后端。可能吗?

最简单的方法应该是根据需要确定用户值

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

并在控制器内重定向:

$this->redirect(Yii::app()->createUrl(Yii::app()->getUser()->getState('LoginReturnUrl')));
请在配置文件(
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:

在main.php中


loginUrl必须用数组声明

当用户转到前端和后端时,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',
    ),
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('*'),
        ),
    );
}
'components' => [
    ...
    'user' => [
        'identityClass' => 'app\models\User',
        'loginUrl' => [ 'YourController\YourLogin' ],
    ],
]