Yii Framework Forum: Call To A Member Function Getdata() On A Non-Object - Yii Framework Forum

Jump to content

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

Call To A Member Function Getdata() On A Non-Object Rate Topic: -----

#1 User is offline   radoo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 05-September 11
  • Location:Bucharest / Romania

Posted 10 October 2012 - 06:18 AM

It seems I am having a problem passing the right format to a widget. Might be trivial, but i cannot figure it out.
I am using the code to try to display some data referenced in a model with a foreign key ($model has a one to many foreign key to "referencedTable" data).

    $this->widget('bootstrap.widgets.TbListView',array(      
  	'dataProvider'=> $model->referencedTable,        	
	'itemView'=>'_someview',    
	)
);


The problem is with the data provider and I have a clue why, but I don't know what is the yii way to approach this.
The current error is:
    Fatal error: Call to a member function getData() on a non-object in
    framework/zii/widgets/CBaseListView.php on line 108

Small web application software company.
Using Yii as the framework of choice.
0

#2 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 916
  • Joined: 20-April 11
  • Location:India

Posted 10 October 2012 - 06:42 AM

u need data from model referencedTable?

$data = referencedTable::model()->findAll();

$this->widget('bootstrap.widgets.TbListView',array(      
        'dataProvider'=> $data,               
        'itemView'=>'_someview',    
        )
);


is this u mean?
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#3 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 916
  • Joined: 20-April 11
  • Location:India

Posted 10 October 2012 - 06:43 AM

or like this

$data = new referencedTable;

$this->widget('bootstrap.widgets.TbListView',array(      
        'dataProvider'=> $data,               
        'itemView'=>'_someview',    
        )
);

Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#4 User is offline   radoo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 05-September 11
  • Location:Bucharest / Romania

Posted 10 October 2012 - 07:51 AM

View PostRajith R, on 10 October 2012 - 06:43 AM, said:

or like this

$data = new referencedTable;

$this->widget('bootstrap.widgets.TbListView',array(      
        'dataProvider'=> $data,   			
        'itemView'=>'_someview',    
        )
);



yes. along those lines, but the problem here is that the referencedTable is a one-to-many relationship from my original table.
Basically it's something like this:
- table1 : members table
- table2: posts table (many for each member)
so in $model i have one record from the table1 (members table, details of one author)
in $model->referencedTable, through the model methods generated by giix i have all posts from table2 (posts table).
and I want to display the posts, in the member view, using a ListView widget.
I know i can do something like
$data = referencedTable::model()->findAll();

and add a condition to get only the posts for the member I am displaying, but since i already have all the information in $model->referenceTable it seems redundant to ask for it again, right?
And many thanks for helping out Rajith!
Small web application software company.
Using Yii as the framework of choice.
0

#5 User is offline   radoo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 05-September 11
  • Location:Bucharest / Romania

Posted 10 October 2012 - 08:01 AM

Actually, i tried this:
$data = Text::model()->findAll("ref_user_id=".$model->id);
$this->widget('zii.widgets.CListView',
	array(
        'dataProvider'=> $data,
        'itemView'=>'_textview',    )
);

and the sql runs just fine but it seems the TbListView expects some other type of data, since it gives me the exact same error. Any clues?
    Fatal error: Call to a member function getData() on a non-object in

Small web application software company.
Using Yii as the framework of choice.
0

#6 User is offline   radoo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 05-September 11
  • Location:Bucharest / Romania

Posted 10 October 2012 - 08:25 AM

Ok. So the problem is that it seems that the CListView requires the data provided to be ActiveRecord, not anything else.So when using
$data = new CActiveDataProvider (bla bla);

everything is ok.
Now the question remains: Can i pass a non ActiveDataProvider to the CListView widget? And how?
Small web application software company.
Using Yii as the framework of choice.
0

#7 User is offline   kokomo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 289
  • Joined: 23-July 10

Posted 10 October 2012 - 08:27 AM

From the CListView docu:

Quote

CListView should be used together with a data provider, preferrably a CActiveDataProvider.

You are passing ActiveRecord objects instead of a class implementing IDataProvider to CListView dataProvider property.

This post has been edited by kokomo: 10 October 2012 - 08:33 AM

0

#8 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,997
  • Joined: 16-February 11
  • Location:Japan

Posted 10 October 2012 - 09:48 AM

We don't give an array of data directly to a CListView. Instead, we give it a data provider which will provide an array of data. That's how the CListView is designed.

http://www.yiiframew...ivedataprovider
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