Fuad Ibrahimov
Fuad Ibrahimov

Reputation: 512

Render view Yii2

How do you render a view file in the profile module's index view file. I tried this:

<?=$this->render('/product/product/_search')?>

This is the error I get:

The view file does not exist: C:\OpenServer\domains\zuppermart\frontend\modules\profile\views\product/product/_search.php`

I also tried <?=$this->render('//product/product/_search')?>

And I get this error:

The view file does not exist: C:\OpenServer\domains\zuppermart\frontend\modules\profile\views\profile\modules//product/product/_search.php

Upvotes: 7

Views: 25729

Answers (3)

Farid Abbas
Farid Abbas

Reputation: 294

A simple solution to this kind views error is to use views base path i.e by using @app/views/: <?=$this->render('@app/views/product/product/_search')?>

Upvotes: 0

Mahmut Aydın
Mahmut Aydın

Reputation: 869

in yii2, we can use render like this :

$this->render('contact',['model'=>$model]);

and render partial:

Yii::$app->controller->renderPartial('myview');

Upvotes: 1

arogachev
arogachev

Reputation: 33548

According to given paths, it should be like this (absolute path specified via alias):

<?= $this->render('@frontend/modules/product/_search') ?>

But note that you are trying to render view from another module, I think it's better to create widget instead.

Official docs:

Upvotes: 16

Related Questions