Trying To Get Property Of Non-Object

Hi All,

I have used bootstrap.widgets.TbGridView in my admin view to display records. I have model SALE join with CLIENT model. I can sale with client id and as well as without client id. When I sale without client id and navigate to admin view, then i get "Trying to get property of non-object", it because there is no such client in CLIENT model with client id 0. Following is the VIEW and model code:

VIEW (admin.php)

$this->widget(‘bootstrap.widgets.TbGridView’, array(

'type'=>'striped bordered condensed',







				'value' => 'Clients::model()->find($data->client_id)->name'    				






        'htmlOptions'=>array('style'=>'width: 50px'),



    				'delete' => array(

    						//'url'=>'Yii::app()->controller->createUrl("ports/delete", array("id"=>$data[id],"command"=>"delete"))',







MODEL CODE (sale model)

public function rules()


	// NOTE: you should only define rules for those attributes that

	// will receive user inputs.

	return array(

		array('sale_date, productid, sale_quantity, sale_price', 'required'),

		array('status', 'numerical', 'integerOnly'=>true),

		array('stock_quantity', 'numerical'),					

		array('client_id, user_id', 'length', 'max'=>20),

		array('discount', 'length', 'max'=>18),

		array('remarks', 'length', 'max'=>200),

		array('edt', 'safe'),

			array('sale_quantity', 'validateQty'),

		array('sale_quantity','compare','compareValue'=>'0','operator'=>'>','message'=>'Quantity must be greater than 0'),

		array('sale_price','compare','compareValue'=>'0','operator'=>'>','message'=>'Sale price must be greater than 0'),

		// The following rule is used by search().

		// @todo Please remove those attributes that should not be searched.

		array('id, sale_date, client_id, discount, remarks, user_id, status, sdt, edt', 'safe', 'on'=>'search'),



public function search()


	// @todo Please modify the following code to remove attributes that should not be searched.

	$criteria=new CDbCriteria;








	$criteria->addCondition('edt is null');


	return new CActiveDataProvider($this, array(





To put condition for client id



	'value' => '($data->client_id != "")?Clients::model()->find($data->client_id)->name:""' 




I have tried this already but I am getting same error.



                    'value' => '(isset($data->client_id) && $data->client_id != "")?Clients::model()->find($data->client_id)->name:""' 


I have tried this as well, but still I am getting "Trying to get property of non-object" error. I think I need to change something in Sale Search function because Gridview dataprovider is search of sale model.