Yii2 dektrium用户新动作

时间:2016-06-21 08:10:36

标签: yii2 yii2-advanced-app yii2-user

我在高级模板中使用dektrium yii2-user。我想在SettingsController中添加新动作。

我做了什么:

覆盖SettingsController。创建/frontend/user/SettingsController.php

namespace frontend\controllers\user;

use dektrium\user\controllers\SettingsController as BaseSettingsController;

class SettingsController extends BaseSettingsController
{

    public function actionMyview()
    {
        $this->render('myview');
    }
}

创建了新视图/frontend/views/user/settings/view/myview.php 并更改了组件部分中的/common/main.php

    'view' => [
        'theme' => [
            'pathMap' => [
                '@dektrium/user/views' => '@frontend/views/user'
            ],
        ],
    ],

但它不起作用。当我访问mysite.com/user/settings/myview时,我看到空白页面没有错误。 另外我不知道如何覆盖行为,所以我直接在/vendor/dektrium/yii2-user/controllers/SettingsController.php中添加了myview的访问规则

我该怎样做对吗? 感谢。

1 个答案:

答案 0 :(得分:1)

添加:

'user' => [
    'class' => 'dektrium\user\Module',
    //...
    'controllerMap' => [
        'settings' => [
            'class' => 'frontend\controllers\user\SettingsController',
            'layout' => '@app/views/layouts/main'
        ]
    ]
]

我明白了!你忘了这是return

public function actionMyview()
{
    return $this->render('myview');
}