Multi CGridview in one page

I have a model Person which has many Cars. In Person page I want to display all the cars he has … so I need to display CGridView on my Person page.

I did that like this

But, it seems the search wont work (it still not returning the correct result) and also for the buttons, it still using Person controller (I want to use Car controller for view, edit and delete)

How to change the default controller in CGridView ?

Hi nightingale,

In Person controller:

public function actionView($id)


    $model = loadModel($id);           // load the person

    $carModel = New Car('search');     // container of search parameters for car

    $carModel->unsetAttributes();      // clear all search parameters

    $carModel->person_id = $model->id; // just search cars that belong to the person

    if (isset($_GET['Car'])) {         // check for inputs

        $modelCar->attributes = $_GET['Car'];  // set search parameters


    $this->render('view', array(

        'model' => $model,

        'carModel' => $carModel,



In view script of Person:

<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>

<div class="search-form" style="display:none">

<?php $this->renderPartial('/car/_search',array(


)); ?>

</div><!-- search-form -->

<?php $this->widget('zii.widgets.grid.CGridView', array(








            'viewButtonUrl' => 'array("car/view", "id"=>$data->id)',

            'updateButtonUrl' => 'array("car/update", "id"=>$data->id)',

            'deleteButtonUrl' => 'array("car/delete", "id"=>$data->id)',



)); ?>

You should have misunderstood the ‘dataProvider’ property of CActiveDataProvider.

Please take a look at the following wiki. :)

@sofark: thank you very much … it works now …

Thanks for the article as well …