guys…
i have an admin back end where i need to display some values from another table.
I am using grid view to display the data.
how can i do it…
guys…
i have an admin back end where i need to display some values from another table.
I am using grid view to display the data.
how can i do it…
Is there a dependency between the data that you show in the view and the data, you want to show? Maybe such a kind like model B has extra data for model A. Then you could create a function in model A that extract the data of model B and you can use this function to show it on the backend site.
If there isn’t a dependency,maybe you can render the both models and show them in different grid views.
thanks for the reply riff
The condition is that…
i have three tables A,B,C
i am displaying the values in A.
A has link with B and B has with C.
In A i have to get the values from C.
First make sure you can give a proper relation on DB and display grid view
like for ex…
1)model.php
public function relations() {
return array(
'users' => array(self::BELONGS_TO, 'users', 'user_id'), //relation view
);
}
2)admin.php
array(
'name'=>'user_id',
'value'=>'$data->users',
or
'value'=>'Users::Model()->FindByPk($data->user_id)->username', //display the grid view
),
3)Then after filer search code
=>put your code in serch function
if(isset($this->user_id) && !empty($this->user_id)){
$criteria = new CDbCriteria;
$criteria->select = 't.*, tu.* ';
$criteria->join = ' LEFT JOIN `users` AS `tu` ON t.user_id = tu.id';
$criteria->addCondition("username='".$this->user_id."'");
}
If you have relations set up between your tables then you can do this in the search() function of model-A (the Cgridview display A models):
If you want all columns from C:
$criteria->with = array(
'relation_from_A_to_B' => array(
'with' => array(
'relation_from_B_to_C' => array(),
),
),
);
If you want specific column(s) from C:
$criteria->with = array(
'relation_from_A_to_B' => array(
'with' => array(
'relation_from_B_to_C' => array(
'select'=>'C_column',
'order' =>'C_column ASC'
),
),
),
);
Also check out this wiki