Flow control rendering


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";




echo 'Some big data';

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


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