S
S
Sergey Beloventsev2017-08-09 13:07:50
Yii
Sergey Beloventsev, 2017-08-09 13:07:50

Why is my parent view rendering?

installed the application https://github.com/dektrium/yii2-user inherited from the controller
in the config like this

'user' => [
            'class' => 'dektrium\user\Module',
            'adminPermission' => 'admin',
            'modelMap' => [
                'User' => 'app\models\User',
            ],
            'controllerMap' => [
                'admin' => 'app\controllers\AdminController'
            ],
        ],

create controller inherit
use app\models\UsersSearch;
use dektrium\user\controllers\AdminController as BaseAdminController;

class AdminController extends BaseAdminController
{
    
    public function actionIndex()
    {
        $searchModel  = new UsersSearch();
        $dataProvider = $searchModel->search(\Yii::$app->request->get());

        return $this->render(\Yii::getAlias('index'), [
            'dataProvider' => $dataProvider,
            'searchModel'  => $searchModel,
        ]);
    }
}

in the views folder I create the admin folder there I create the index.php view,
but for some reason this view is rendered, why /vendor/dektrium/yii2-user/views/admin/index.phpdon’t tell me and how to correctly configure the render to the app/views/admin folder

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Decadal, 2017-08-09
@Decadal

And for your interest, look in the debug at the viewPath field of your child controller, or look at the source of the parent and find the viewPath there, most likely it is defined there.
Redefine the $viewPath field directly in the child controller:

class AdminController extends BaseAdminController
{
    public $viewPath = ''; //ваш путь, если он может быть прописан напрямую
    public __construct( /*внимательно - скопируйте сюда параметры родителя*/) {
        $this->viewPath = Yii::getAlias('@app').'/views/admin';   //ваш путь, если нужно задать через алиас
        parent::__construct( /* передайте все параметры без изменений */); 
    }

    public function actionIndex()
    {
        $searchModel  = new UsersSearch();
        $dataProvider = $searchModel->search(\Yii::$app->request->get());

        return $this->render('index', [
            'dataProvider' => $dataProvider,
            'searchModel'  => $searchModel,
        ]);
    }
}

M
Maxim Timofeev, 2017-08-09
@webinar

Why
and what is there?
try
or
\Yii::getAlias('@app/views/admin')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question