Cgridveiw To Display

Hi all,

when a person clicks on a category display him all products under category in a gridview

view preson




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

'id'=>'admin-grid',

'dataProvider'=>$model->SelectedCategoryProducts,

'filter'=>$model,

'columns'=>array(

    'Name',

    'Model',

    'Brand',

    'Price',


    array(

        'class'=>'CButtonColumn',

    ),

),

 )); ?>[code]

[/code]

controller person


 public function actionProductcategory($id)

      { 




$model=new Product;


$this->render('productcategory',array('model'=>$model,));




      }

model in products




 public function SelectedCategoryProducts($id)

{

    $sql="select name,model,price,brand from fc_product 

    WHERE category=".$id;

    $connection=Yii::app()->db;

    $command=$connection->createCommand($sql);

    $cat_product=$command->queryAll();


 return new CSqlDataProvider($sql, array(


'sort' => array(

    'attributes' => array(

         'Name', 'Model', 'Brand','Price',

    ),

),

'pagination' => false));

}


 CException


 Property "Product.SelectedCategoryProducts" is not defined.



PLEASE HELP! am losing may mind on this … not able to display gridview

dont use this code in model. just write it in your view like this

[color="#006400"]$sql="select name,model,price,brand from fc_product

WHERE category=&quot;.&#036;id;


&#036;result=Yii::app()-&gt;db-&gt;createCommand(&#036;sql)-&gt;queryAll();  

$data = CSqlDataProvider($result);[/color]

set dataprovider=>$data,

you can also write this using CDataprovider. i prefer this one. :)