Hello all – I apologize if this has been covered before but I’ve googled and searched the forums back and forth and can’t find an example. I’m trying to create a link from an admin.php CGridView into an another admin gridview but have the target CGridView only return rows that match the id (foreign key) of the row selected in the first CGridView.
A simplified example could be Customers and Servers. Customers have many servers but servers only have one customer. I’ve created FK relations with InnoDB tables and generated CRUD pages using Gii. Server contains the customer_id as a FK. This has created proper relations in my models but I can seem to find the best practice for creating a link to the Servers admin page from the customers admin page that results in the CGridView on the server admin page only returning servers for that customer id.
Do you mean that in one admin page, you can click on a link that will bring you to a 2nd page for records on that link? If so, you could just do something like this in your 1st gridview:
Thanks for the quick reply!! This is where I’ve been having the problem - I’ve formed the link to the server admin page but once there I have trouble getting actionAdmin to only return records that match the foreign key. Using your suggestion I chaged the actionAdmin in ServerController.php to:
public function actionAdmin($relatedID=null)
{
//$model=new Server('search');
$model=new Server;
$model->relatedAttribute = $relatedID;
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Server']))
$model->attributes=$_GET['Server'];
$this->render('admin',array(
'model'=>$model,
));
}
but this tosses the exception Property “Server.relatedAttribute” is not defined. It’s worth noting that both $model=new Server(‘search’); and $model=new Server; return “Server.relatedAttribute” is not defined. The model is generated by Gii so perhaps it’s missing something?