sure
its a big piece of code, but I’ll explain it
first transform the code into criteria, use in the select "as" to define the keys names
then define the keys as public variables of the model and use it in the compare method (also add it to the rules as safe on search)
then in the grid view use the defined keys as columns
here is the code of how I did
declare the variables that you will use later
public $e_Tipo,$e_Serial,$e_Marca,$e_Modelo;
public $u_Nombre_Completo,$u_Sede,$u_Cargo;
Search function
public function searchRel()
{
$criteria=new CDbCriteria;
$criteria->select='
t.OC,
t.Instalacion,
t.Responsable_Une,
t.Telefono,
t.Agendamiento,
t.Observaciones,
usuarios.Nombre_Completo as u_Nombre_Completo,
usuarios.Cargo as u_Cargo,
usuarios.Sede as u_Sede,
tipo_equipos.Tipo as e_Tipo,
tipo_equipos.Serial as e_Serial,
tipo_equipos.Marca as e_Marca,
tipo_equipos.Modelo as e_Modelo';
$criteria->with=array('tipo_equipos','usuarios');
$criteria->compare('t.OC',$this->OC);
$criteria->compare('t.Serial',$this->Serial,true);
$criteria->compare('t.Identificacion',$this->Identificacion);
$criteria->compare('t.Instalacion',$this->Instalacion,true);
$criteria->compare('t.Responsable_Une',$this->Responsable_Une,true);
$criteria->compare('t.Telefono',$this->Telefono,true);
$criteria->compare('t.Agendamiento',$this->Agendamiento,true);
$criteria->compare('t.Observaciones',$this->Observaciones,true);
$criteria->compare('tipo_equipos.Tipo',$this->e_Tipo,true);
$criteria->compare('tipo_equipos.Serial',$this->e_Serial,true);
$criteria->compare('tipo_equipos.Marca',$this->e_Marca,true);
$criteria->compare('tipo_equipos.Modelo',$this->e_Modelo,true);
$criteria->compare('usuarios.Nombre_Completo',$this->u_Nombre_Completo,true);
$criteria->compare('usuario.Cargo',$this->u_Cargo,true);
$criteria->compare('usuario.Sede',$this->u_Sede,true);
return new CActiveDataProvider(get_class($this),array(
'criteria'=>$criteria
));
}
the relations
public function relations()
{
return array(
'usuarios'=>array(self::BELONGS_TO,'Usuarios','Identificacion'),
'tipo_equipos'=>array(self::BELONGS_TO,'TipoEquipos','','on'=>'t.OC=tipo_equipos.OC'),//the foreign key is not primary
);
}
the grid
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$model->searchRel(),
'filter'=>$model,
'columns'=>array(
'OC',
'Instalacion',
'Responsable_Une',
'Telefono',
'Agendamiento',
'Observaciones',
'u_Nombre_Completo',
'u_Cargo',
'u_Sede',
'e_Tipo',
'e_Serial',
'e_Marca',
'e_Modelo',
),
));
controller
function actionConsulta1(){
$model=new ControlReposHabUne('search');
$model->unsetAttributes();
if(isset($_GET['ControlReposHabUne'])){
$model->attributes=$_GET['ControlReposHabUne'];
}
$this->render('consulta1',array(
'model'=>$model,
));
}