use condition

Hello,

I upgrade Yii 1.0 to Yii 1.1, but I don’t understand how to use condition in view file. Here is my view file

<?php $this->widget(‘zii.widgets.grid.CGridView’, array(

'dataProvider'=&gt;&#036;dataProvider,


'columns'=&gt;array(


	array(


		'class'=&gt;'CButtonColumn',


	),





	'name',


	'address',


	'phone',


	'email',


	


),

)); ?>

I want to use this condition

<?php if ($model->User_id == Yii::app()->user->id){ ?>

Can anyone help me?

see this http://www.yiiframew…iveDataProvider

public function actionAdmin()

{


	&#036;dataProvider=new CActiveDataProvider('table1', array(


		'criteria'=&gt;array(


		'condition'=&gt;'a_id = 1  AND User_id = ?',


		 ),


		'pagination'=&gt;array(


	       'pageSize'=&gt;20,


	       ),


		));


	&#036;this-&gt;render('admin',array(


		'dataProvider'=&gt;&#036;dataProvider,


	


	));


}

How to use $model->User_id == Yii::app()->user->id) in the condition?




public function actionAdmin()

	{

		$dataProvider=new CActiveDataProvider('table1', array(

			'criteria'=>array(

			'condition'=>'a_id = 1  AND User_id = '.Yii::app()->user->id  ,

			 ),

			'pagination'=>array(

		       'pageSize'=>20,

		       ),

			));

		$this->render('admin',array(

			'dataProvider'=>$dataProvider,

		

		));

	}






I got this error

CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘’ at line 1

in my case: Yii::app()->user->id is a string

maybe you should use

Yii::app()->user->getState(‘User_id’) and in the class UserIdentity, set this state

This should not matter.

Your error looks like your Yii::app()->user->id contains no value which causes a broken condition clause.

In fact, if the user is not authenticated, Yii::app()->user->id defaults to NULL.

Either, check if your user is NULL before inserting it into your condition, or use (int)Yii::app()->user->id to guarantee an integer value (NULL will be 0).