View - beginBlock auth check vs if/else

If I am to be building a UI which has standard and administrative elements in it, is it better to be written with the auth check result passed as renderInPlace or should I be using If/Else blocks.

If I am to assume correctly, the if/else is more secure because the block would never come to be unless auth is checked compared to render but not output?

Eg:




$this->beginBlock('something', \Yii::$app()->user->can('doSomething'));

    echo "Something";

$this->endBlock();



or




if (\Yii::$app()->user->can('doSomething')) {

    echo "Something";

}



Thanks!

The if statement

  • is designed for and does exactly what you need

  • is absolutely reliable[sup]*

[/sup]- is the simplest possible solution.

Why would you overcomplicate things?

[sup]*[/sup]Don’t get me wrong, I’m not saying that Yii’s code is unreliable.

I have been using the If/Else block for the very reasons you mentioned - but that being said, Yii adds a number of features which are less simple in the name of flexibility, best practices, ease of use…

Thanks for confirming my suspicions!