Modelname and its behaviors do not have a method or closure named "getData". in yii

5.8k Views Asked by At

i dont know where am i going wrong i did play round with it but did not achieve anything.

i wanna display data using cListview but unable to do so i have a function in model

Model

      public function psearch1()
{
    $name=$_GET['search'];
    $criteria=new CDbCriteria;
    $criteria->alias="t";
    $criteria->select="t.id,t.name,t.model";
    $criteria->condition='name LIKE "%'.$name.'%"';
    return new CActiveDataProvider($this,array('criteria'=>$criteria,));

}

controller

 public function actionPsearchindex()
{
    $dataProvider=new Modelname('psearch');


    $this->render('psearchindex',array(
        'dataProvider'=>$dataProvider,
    ));
}

view

psearchindex

  $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_psearchindex1',



  ));

_psearchindex

  echo CHtml::encode($data->name);

when i execute i get the following

error

Modelname and its behaviors do not have a method or closure named "getData".

this is my first attempt am doing so but unable to figure out whats wrong

1

There are 1 best solutions below

1
On BEST ANSWER

a new model is not a data provider, call your custom search on it

public function actionPsearchindex()
{
    //$dataProvider=new Modelname('psearch');// a new model is not a data provider
    $model = new Modelname('psearch'); 

    $this->render('psearchindex',array(
        'dataProvider'=>$model->psearch1(), // this will give you a data provider that you can use
    ));
}