PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 30, 2022

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

 January 30, 2022     cactivedataprovider, clistview, dataprovider, yii     No comments   

Issue

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


Solution

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
    ));
}


Answered By - Developerium
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing