Yii Framework Forum: Cgridveiw To Display - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Cgridveiw To Display

#1 User is offline   emmi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 48
  • Joined: 02-December 13

Posted 26 December 2013 - 05:26 AM

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
0

#2 User is offline   Ravi_Hirani 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 27-February 13

Posted 03 January 2014 - 07:52 AM

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

$sql="select name,model,price,brand from fc_product
WHERE category=".$id;
$result=Yii::app()->db->createCommand($sql)->queryAll();

$data = CSqlDataProvider($result);


set dataprovider=>$data,

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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users