YII2从前端

时间:2015-04-27 06:13:42

标签: yii2 yii2-advanced-app yii-url-manager

在yii2中安装了高级模板之后,我从前端获得了用户注册,但我希望它在注册后重定向到后端。怎么办呢?

public function actionSignup()
{
    $model = new SignupForm();
    if ($model->load(Yii::$app->request->post())) {
        if ($user = $model->signup()) {
            if (Yii::$app->getUser()->login($user)) {
                return $this->goHome(); // I WANT TO CHANGE THIS TO REDIRECT TO LOCALHOST/MYAPP/BACKEND/WEB
            }
        }
    }

    return $this->render('signup', [
        'model' => $model,
    ]);
}

更新 这是urlmanager

    'urlManager' => [
    'class' => 'yii\web\urlManager',
    'showScriptName' => false,
    ],
    'urlManagerBackend' => [
        'class' => 'yii\web\urlManager',
        'showScriptName' => false,
        'baseUrl' => 'http://localhost/ncddp/backend/web/index.php',
    ],

1 个答案:

答案 0 :(得分:2)

您可以urlManagerfrontend配置单独的backend组件:

'urlManager' => [
    'class' => 'yii\web\urlManager',
    'enablePrettyUrl' => true,
    'showScriptName' => false,
],
'urlManagerBackend' => [
    'class' => 'yii\web\urlManager',
    'enablePrettyUrl' => true,
    'showScriptName' => false,
    'baseUrl' => 'http://admin.site.com',
],

在应用程序配置中输入components部分。

然后你可以这样使用它:

Yii::$app->urlManagerBackend->createUrl(...);

使用重定向:

return $this->redirect(Yii::$app->urlManagerBackend->createUrl(...));

相关链接: