M
M
Maxim2013-12-04 23:56:30
Yii
Maxim, 2013-12-04 23:56:30

How to specify dataProvider when using TbGridView yii-booster addon?

The selection from the database is:

$data = Players::model()->findAll('Member=:Member',array(':Member'=>5));

If you specify dataProvider => $data, then an error pops up that there is no getData method.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2013-12-05
@Frapsy

So drag the data provider from the database

$criteria = new CDbCriteria;
$criteria->compare('Member', 5);
$dataProvider = new CActiveDataProvider('Player', array(
    'criteria' => $criteria,
    'pagination' => false
));

D
duke_nu, 2013-12-19
@duke_nu

'dataProvider'=>$model->search(),
  'filter'=>$model,

in controller:
$model=new Model('search');
         $model->unsetAttributes();  // clear any default values
        if (isset($_GET['Model']))
            $model->attributes = $_GET['Model'];
        
        if (isset($_GET['ajax'])) 
           {
       
        $this->renderPartial('_modelgrid',array(
            'model'=>$model,
          ));
        Yii::app()->end();
           }
       else
         
      $this->render('index',array('model'=>$model));

In the model:
If the model is generated by a generator, then the search() method. will be by default
if not, then the search() method should return:
return new CActiveDataProvider($this, array(
      'criteria'=>$criteria,
    ));

in $criteriaCDbCriteria

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question