Flow control rendering

Hi.

How can I say Yii2 brake the current view and return to layout?

I have a view which can’t have all data and I want to do something like this in native PHP


if (empty($var)) {

   echo "Sorry that's all we have for you";

   

   return;


}




echo 'Some big data';

Can I use return statment or maybe Yii2 have something like $this->enoughGoToNextView(); ?

Thanks

This will work just as you expect, when it is written in your view script. Just try it.

I used this.


<?php if (empty($var)):     ?>

    Some content

<?php return; endif; ?>


Some big content

Works fine, but I don’t know if that normal practice with Yii2

I think it’s a matter of taste, but I would write




<?php if (empty($var)): ?>

    Some content

<?php else: ?>

    Some big content

<?php endif; ?>



Thanks for the replies