i searched the forum and found a myriad of topics regarding my problem, but i simply cannot work it out.
I want to search for users in a City.
My relations: User HAS_ONE Profile, Profile HAS_ONE City
class User extends CActiveRecord {
...
public $search_location;
public $search_gang;
...
$criteria->with=array('profile.city');
if(strlen($this->search_location))
$criteria->addSearchCondition('profile.city.name',$this->search_location,true);
// in my view
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'user-grid',
'dataProvider'=>$model->active()->search(),
'filter'=>$model,
'columns'=>array(
'id',
'name',
//'search_location',
array(
'name'=>'search_location',
'value'=>'$data->profile->city->name',
'header'=>'Location',
),
),
)); ?>
The city name is displayed in the grid and the search box is available, but when i enter any city name in the search box, no search is performed. The list shows still all users.
This is my first yii experience, so any suggestion is appreciated.
Querying SQL:
SELECT `t`.`id` AS `t0_c0`, `t`.`username` AS `t0_c1`,
`t`.`email` AS `t0_c2`, `t`.`password` AS `t0_c3`, `profile`.`user_id` AS `t1_c0`,
`profile`.`city_id` AS `t1_c1`, `city`.`id` AS `t2_c0`, `city`.`name` AS `t2_c1`,
`city`.`latitude` AS `t2_c7`, `city`.`longitude` AS `t2_c8`
FROM `user` `t`
LEFT OUTER JOIN `profile` `profile` ON (`profile`.`user_id`=`t`.`id`)
LEFT OUTER JOIN `city` `city` ON (`profile`.`city_id`=`city`.`id`) WHERE
(city.name LIKE :ycp0) LIMIT 10. Bind with parameter :ycp0='%%'
Now the condition is attached, but when i enter a value in the search box i have still no success.
Parameter :ycp0 will not get the entered value but stays ‘%%’.