Why executing a line after a conditional if, regardless it's results ?




1 $(document).ready(function(){

2   if('<?= Yii::app()->controller->action->id?>' == 'update'){

3        if('<?= Yii::app()->user->id;?>' != '<? if(isset($model)) echo $model->createUser->id; ?>'){




Yii::app()->controller->action->id

IS NOT equal to update;

My question is:

If


Yii::app()->controller->action->id

is not equal to update, why do I get a “Trying to get property of a non object on line 3 ?” I mean, yes, I know there’s no object property named like that, but I’m not getting why is Yii checking that line anyway?

What am I missing here ?

try:

[list=1]

[*]use <?php instead of <?;

[*]check if non object ahead of time, using isset() to assign a variable, then use this variable in your if statement;

[/list]

Hello,

I’m not using <? but <?= with is the same as <?php echo.

The issue relies on my bad server side and client side interpretation. The third (3) IF will ALWAYS run, regardless the javascript conditionals, because, it will run BEFORE the javascript arrives to the client for interpretation. Hence, I’m always getting that error.

What would be a proper way to deal with this ? Should we use some sort of intermediary language on this case, like json ?

pretty confusing if you mix php and js this way, would the following be a option if you could not find a better way?


<?php if ($condition) {?>

$js1;

<?php } else {?>

$js2;

<?php } ?>

Thanks. It was a isset related issue.

Instead of:


<? if(isset($model)) echo $model->createUser->id; ?>')

I have:


<? if(isset($model->createUser->id)) echo $model->createUser->id; ?>')

I will take into consideration your thoughts about separating things.

Cheers,

mem