User Defined Functions and Criteria

I have a table -> tbl_staff (id , name)

and I have written a function in my staff model :

public function oddOrEven ()

{

if ($this->id % 2 == 0) return ‘even’

else return ‘odd’;

}

now I want to return all odd recoeds and use a dataprovider to show these records

Note : I DONT WANT to use the SQL statements in the criteria like this

$dataProvider=new CActiveDataProvider(‘MstTender’,

array(

'criteria' => array( 


    'condition'=>'id % 2 = 1,                    


),


)		


);

I want to use my oddOrEven directly something like this :

$dataProvider=new CActiveDataProvider(‘MstTender’,

array(

'criteria' => array( 


	'condition'=>oddOrEven  .'=odd',                    


),


)		


);

but it is not correct can u guide plz?

You should use the condition in dataprovider, this is the correct way.

There is no meanining in select both even and odd records and then display only a part, is logically incorrect.

If you are looking for an elegant way of setting condition, take a look at scopes.

can u plz give an example how can I use my own function to filter the records via scopes?