render a view from another controller, yii

33,680

Solution 1

try this

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

Solution 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

Share:
33,680
Cedric
Author by

Cedric

Open to new opportunities Fond of Linux ? Can't remember how to use a command ? linux-commands-examples.com Your army-swiss knife for email address extraction : www.extractemailaddress.com Are you looking to change job ? Thousands of kickass tricks to help you in your job search : getthisjobfast.com

Updated on August 08, 2020

Comments

  • Cedric
    Cedric over 3 years

    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.