29

The controller:

controllers
|-FooController.php
|-BarController.php

The views:

view
|-foo|
|    |-index.php
|    |-error.php
|
|-bar|
     |-index.php

How to render the error.php view with an action of the bar controller? I have tried:

$this->render('foo/error');

But it doesn't work.

Cedric
  • 5,135
  • 11
  • 42
  • 61

2 Answers2

63

try this

$this->render('//foo/error');
Let me see
  • 5,063
  • 9
  • 34
  • 47
2

If you don't echo it, you will get a blank page. The correct way is

<?=
   $this->render('//foo/error');
?>

or

<?php
     echo $this->render('//foo/error');
?> 

This also works for Yii2

ovicko
  • 2,242
  • 3
  • 21
  • 37