I have the following scenarion
I have 2 mysql tables where I need to search within,
In the 2nd table I have a column with name type with contains numbers 1-4, 1 = Normal user, 2 = Sales user etc. Now the corresponding text is not in the database, the text that belong to these values are defined as constants and thats why I need to dropdown. now if I select a value in the dropdown list the search is not executing
My view looks like this
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'user-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array(
'name'=>'acl_id',
'filter'=>CHtml::dropDownList('user[acl_id]',$data->acl_id,$arr),
'value'=>'CHtml::encode(user::model()->getTypeByText(acl::model()->getACL($data->acl_id)))',
),
array(
'name'=>'region_id',
'type'=>'raw',
'value'=>'CHtml::encode(region::model()->getRegion($data->region_id))',
),
array(
'name'=>'acl_id',
'header'=>'Username',
'type'=>'raw',
'value'=>'CHtml::encode(acl::model()->getUsername($data->acl_id))',
),
'name',
'surName',
'email',
'cell',
'createDate',
'modDate',
array(
'class'=>'CButtonColumn',
),
),
)); ?>
The search within the model looks like below, please note that the value selected is nopt pulling throug to criteria->addInCondition(‘acl.type’,array($this->acl_id)); , if I replace $this->acl_id with a number the search works, but this needs to be dynamic,
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->with = array('region','acl');
$criteria->compare('region.region',$this->region_id,true);
if(!empty($this->acl_id)){
$criteria->addInCondition('acl.type',array($this->acl_id));
}
$criteria->compare('t.name',$this->name,true);
$criteria->compare('t.surName',$this->surName,true);
$criteria->compare('t.email',$this->email,true);
$criteria->compare('t.email2',$this->email2,true);
$criteria->compare('t.cell',$this->cell);
$criteria->compare('t.tel',$this->tel);
$criteria->compare('t.fax',$this->fax);
$criteria->compare('t.createDate',$this->createDate,true);
$criteria->compare('t.modDate',$this->modDate,true);
return new CActiveDataProvider('user', array(
'criteria'=>$criteria,
));
}