CDetailView nullDisplay

I understand nullDisplay is used when an attribute value is null - this works when the attribute value in the DB is null, but not if you manually assign an attribute value to null (in your code). So for example I have the following:

Model:




public function getLocationOptions()

{

	return CHtml::listData(Location::model()->findAll(array('condition'=>'enabled=1')), 'id', 'name');

}

	

public function getLocation()

{

	return array_key_exists($this->location_id, $this->LocationOptions) ? $this->LocationOptions[$this->location_id] : null;

}



CDetailView attribute config:


array(

	'name'=>'location_id',

	'value'=>$model->Location,

),

So in the event that a location_id is no longer present in the database, or that location is not enabled, then I expect it to send a null value to CDetailView. However this is not the case - it is just outputting the actual value. I tried changing null to false, but this just produces a blank output - I want it to produce the default output - i.e. "Not set".

Have you tried to return “Not Set”? the problem is that location_id isn’t null… and that is the attribute it looks for, not being null returns the value specified by you

Lol that would of course work - but not correctly.

Standard nullDisplay output gives you a pink text, so you know it is using nullDisplay - essentially what I’m saying is since we’re returning null then why doesn’t it use nullDisplay?

Oh OK that makes sense. I’ve fixed this - I’ve changed it to:


return array_key_exists($this->location_id, $this->LocationOptions) ? $this->LocationOptions[$this->location_id] : $this->location_id=null;

;D

Good on you mate!