Syntax Error In Expression Of Rowcssclassexpression

Hello,

In following code i am trying set an expression for rowCssClassExpression:




	$this->widget('zii.widgets.grid.CGridView',array(

    	'dataProvider'=>$model->search(),

    	'filter'=>$model,

    	'rowCssClassExpression'=>' if($data->type == 1) return "deleted-row" ',

    	. . . 

    	. . . 

    	. . . 



but get error:




Parse error: syntax error, unexpected T_IF in C:\Apache2\htdocs\yii\framework\base\CComponent.php(607) : eval()'d code on line [i]1[/i]



What’s the correct syntax for rowCssClassExpression?

Dear My Friend

Kindly try the following.




'rowCssClassExpression'=>function($row,$data){

		             if($data->type==1)

			         return "deleted-row";

		        },



Thanks, your suggest is right, but i am amazing what’s the problem of my expression?

it is always good to create a getter method in your model class and call it like this.Which gives more easy approach.




'rowCssClassExpression'=>'$data->getcssClass()',






public function getcssClass(){

    if($this->type==1)

         return "deleted-row";

}



Thanks, i used same way. only i’m prowler what’s the problem of this expression:




'rowCssClassExpression'=>' if($data->type == 1) return "deleted-row" ',

Might be this will work.




'rowCssClassExpression'=>' if($data->type == 1){ return "deleted-row"; }',



didn’t work!


'rowCssClassExpression'=>'$data->type == 1 ? "deleted-row" : ""',

There is no problem with this expression. i want now why IF statement didn’t act?!

See CComponent::evaluateExpression.




	public function evaluateExpression($_expression_,$_data_=array())

	{

		if(is_string($_expression_))

		{

			extract($_data_);

			return eval('return '.$_expression_.';');

		}

		else

		{

			$_data_[]=$this;

			return call_user_func_array($_expression_, $_data_);

		}

	}



Your code would do:


return if($data->type == 1){ return "deleted-row"; };

Which is invalid PHP code.