How to use PHP function in criteria?

I have three tables :

Table Unit

id , title , parent_id

Table Role

id , title , unit_id

Table Staff

id , name , role_id

Table Staff -> belongs to Role through role_id

Table Role -> belongs to Unit through unit_id

each unit record has a parent_id that point to its parent record

I wanna select the Staffs that they are organizationally in a lower place than a particular staff

for example I wanna say selectLowerStaffs (3) --> it means choose all the staff records that they r in a lower place than staff with id = 3

and I prefer to use my Own PHP function to do this and I dont wanna convert my PHP algorythm codes to SQL nor using internal MySQl functions

for this reason I have written a function in PHP now I cant apply it in my model and in my dataprovider

something like :

in Staff Model

public function selectLowerStaffs()


-- a complicated php algorythm that I can not convert it to Sql ---

return -> all lower staff records from staff model with id =3


in Staff Controller

$staff = Staff::model()->findByPk(3);

$model = $staff->selectLowerStaffs();

$dataProvider=new CActiveDataProvider($model, )); or print_r ($model)

but it is not correct and it doesn’t work


Lets be clear…

To get any data from the database you need to issue a SQL command… and you cannot use a PHP function in that command…

It is a new promotion in Microsoft ASP.NET it is LINQ. there, you can use asp codes between ur sql codes I suggest that you Yii developers take a look at it , it is very useful tech Here

anyway u meant that I have no selection? I have to convert all my complicated PHP algorythm to Sql? :(

I don’t know your “complicated PHP algorithm”… but i don’t see why would you get the data by executing a PHP function… by using SQL you get the data in the fastest and best possible way…

on the other hand

you can select all the data you need (even all)… and than process that data row by row using your PHP function… but depending on the number of records this would use too much memory…

Since LINQ - as name suggests - is a part of the programming language, it can’t be implemented at framework level.

You may want to take a look at Doctrine and DQL if you need similar (though not the same) functionality for PHP.

I think u r right but maybe a way!