Hello there, i have been through different pages and different topics to meet my specification, and finally i post here.
What i am trying to do is,
I have a UserProfile and User model.
Entities/Attributes.
UserProfile: id,user_id,first_name, last_name,…
User: username,id
I want to show all entities form UserProfile and User in cgridview and able to search them separately.
so i created a controller action like this.
public function actionControllerAction(){
$model = new UserProfile('search');
$model -> unsetAttributes();
// clear any default values
if (isset($_GET['UserProfile']))
$model -> attributes = $_GET['UserProfile'];
$this -> render('MyView', array('model' => $model ));
}
// CGridView
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'user-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array('name'=>'first_name',
'header'=>"First Name",
'htmlOptions'=>array('style'=>'text-align: center'),),
array('name'=>'user_id',
'header'=>User::model()->getAttributeLabel('username'),
'value' =>'$data->getRelated(\'user\')->username',
'type'=>'raw',
....................
// my Model search function:
$criteria -> compare('first_name', $this -> first_name, true);
$criteria -> compare('user_id', $this->user_id, true);
return new CActiveDataProvider($this, array('criteria' => $criteria, ));
But i am not able to search by username, how can i acheive this?? Help needed !