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

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -