display fields if not empty in PHP/YII -
i used code groovy ... found 'feature' (no idea called it) fun n nice (i heard implemented on c# too).
for example ... want display person neighbour name
i type
println person?.neigbour?.name ;
it means if neighbour empty / blank .. didn't display .
how in php 5/yii?
example:
instead of typing long codes '/>
would better type '/>
in first place think no yii issue, php. assuming, use yii nice models, there go sth this:
if($person && $person->neighbour && !empty($person->neighbour->name)) { echo $person->neighbour->name; }
a shortcut may (not nice):
echo $person ? ($person->neighbour ? ($person->neighbour->name ? $person->neighbour->name : "" ) : "" ) : "";
Comments
Post a Comment