0

I am a newbei in yii, when a person clicks on a category display him all products under that particular category in a gridview

view productcategory

    <?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',
    ),
),
 )); ?>

controller product

    public function actionProductcategory($id)

{

$model= Product::model()->SelectedCategoryProducts($id);
    var_dump($model);


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

} model product

  public function SelectedCategoryProducts($id)
{
    $dataProvider=new CActiveDataProvider('Product', array(
 'criteria'=>array(
                        'select'=>'name,model,price,brand',
        'condition'=>'category=:category',
                        'params'=>array(':category'=>$id),
    )));
    var_dump($dataProvider);
   return $dataProvider;
   }
CException

Property "CActiveDataProvider.sellerSelectedCategoryProducts" is not defined.

PLEASE HELP! I am losing my mind on this ... not able to display in gridview.

Criesto
  • 1,985
  • 4
  • 32
  • 41
Tested
  • 761
  • 4
  • 16
  • 38
  • I guess, 'dataProvider'=>$model->SelectedCategoryProducts, In this line SelectedCategoryProducts is function and need id as parameter. You have to be use like : 'dataProvider'=>$model->SelectedCategoryProducts($id) – naveen goyal Dec 26 '13 at 10:17
  • :) yes, your application is throwing error for this line ; 'dataProvider'=>$model->sellerSelectedCategoryProducts, – Chaulagai Dec 26 '13 at 10:17
  • i did try that PHP notice Undefined variable: id ..... – Tested Dec 26 '13 at 10:18
  • you have to call the function like `$model->SelectedCategoryProducts()` in cgridview – Kumar V Dec 26 '13 at 10:19
  • what should be done to to get it displayed in gridview any idea? – Tested Dec 26 '13 at 10:20
  • @tisha you have to pass id. like 1 in your function which is category id in your case – naveen goyal Dec 26 '13 at 10:20
  • @kumar_v PHP warning Missing argument 1 for Product::sellerSelectedCategoryProducts(), called in D:\wamp\www\testfolder\protected\views\seller\productcategory.php on line 9 and defined – Tested Dec 26 '13 at 10:22
  • ya i am passing category id itself but doesnt wrk :( @naveengoyal – Tested Dec 26 '13 at 10:24

3 Answers3

0

Hope this might help
Controller file

public function actionProductcategory($id)
      { 
$model=new Product;
$this->render('productcategory',array('model'=>$model,
'id'=>$id));
 }


In View file

'dataProvider'=>$model->SelectedCategoryProducts($id),

UPDATE 1

'columns'=>array(
    'name',
    'model',
    'brand',
    'price',

change them to lowercase which are your original column names

Let me see
  • 5,063
  • 9
  • 34
  • 47
0

Pass $id to your view file.

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

Then pass id to model function in ccgridview function.

'dataProvider'=>$model->SelectedCategoryProducts($id),
Kumar V
  • 8,810
  • 9
  • 39
  • 58
0
        $dataProvider=new CActiveDataProvider('Product', array(
     'criteria'=>array(
                            'select'=>'name,model,price,brand',
            'condition'=>'category=:category',
                            'params'=>array(':category'=>$id),
        )));

this can retrieve needed data.... first check that data is perfect ... is it right after that take second step....

Jaimin MosLake
  • 655
  • 1
  • 12
  • 30