Heyho
(M8r 21hukg)
July 17, 2013, 8:31am
1
I have the following code:
$dp=new CArrayDataProvider($model->person->emails);
$this->widget('zii.widgets.grid.CGridView',
array('dataProvider'=>$dp,
'columns'=>array('address',
array('class'=>'CButtonColumn'))));
Where $model->person->emails is
public function relations()
{
return array(
'emails' => array(self::HAS_MANY, 'Email', 'person_id'),
// etc.
Why, when I click the "edit" button of an entry in the resulting grid, do I get this "get_Class() Expects Parameter 1 To Be Object, Array Given" error?
konapaz
(Konapaz)
July 17, 2013, 9:11am
2
Hi Heyho
is the $model the default object that generated by crud ?
In this case you could try something like that
$db =$model->search();
$db = $db->getData();
$db = $db[0]->manyItems;
$db = new CArrayDataProvider($db);
$this->widget('zii.widgets.grid.CGridView',
array('dataProvider'=>$dp,
'columns'=>array('myattribute',
array('class'=>'CButtonColumn'))));
I just tested and it works in my case
Heyho
(M8r 21hukg)
July 17, 2013, 9:55am
3
KonApaz:
Hi Heyho
is the $model the default object that generated by crud ?
In this case you could try something like that
$db =$model->search();
$db = $db->getData();
$db = $db[0]->manyItems;
$db = new CArrayDataProvider($db);
$this->widget('zii.widgets.grid.CGridView',
array('dataProvider'=>$dp,
'columns'=>array('myattribute',
array('class'=>'CButtonColumn'))));
I just tested and it works in my case
I don’t see how it can have worked. $dp would be null.
What is manyItems?
konapaz
(Konapaz)
July 17, 2013, 11:20am
4
please post your action of controller.
if $dp is null you have to wrap my code
if ($dp) {
$db =$model->search();
$db = $db->getData();
$db = $db[0]->manyItems;
$db = new CArrayDataProvider($db);
} else {
$db = new CArrayDataProvider(array());
}
manyItems is an example of my code not yours!
in your project could be the same of $model->person(s)
so you have to find out how can ajusts my code for your needs
Heyho
(M8r 21hukg)
July 17, 2013, 11:39am
5
You never set $dp to anything!
konapaz
(Konapaz)
July 17, 2013, 12:25pm
6
Heyho,
I post a sample of code that I tried but on copy-paste I change a bracket
$db =$model->search();
if ($db) {
$db = $db->getData();
$db = $db[0]->manyItems;
$db = new CArrayDataProvider($db);
} else {
$db = new CArrayDataProvider(array());
}
check also by yourself line by line if something gives null or empty
softark
(Softark)
July 17, 2013, 4:49pm
7
@KonApaz
Heyho is complaining that you set $db but not $dp .
@Heyho
You could have imagined that KonApaz had typed a simplest typo and made a necessary change.
But, on the issue stated in the 1st post, KonApaz’s suggestion seems to be irrelevant. I think it might be because of the difference between CActiveDataProvider and CArrayDataProvider. The “Edit” button seems to try to get the id by “$data->id”. It will work when you use CActiveDataProvider. But it must be “$data[‘id’]” when you use CArrayDataProvider.