mithereal
(Mithereal)
April 24, 2010, 6:56am
1
hello I am running a function in a class (Games) like this
$object=new CActiveDataProvider(‘Games’, array(
'criteria'=>array(
'condition'=>'state_code=:state_code',
'params'=>array(':state_code'=>'AZ'),
),
));
return $object->getData();
}
and the view is
<?php $test=Games::model()->listAvailablegames();
var_dump($test);?>
how do i get the attributes out of the objects in the array,
thx in advance!!
dotangelo
(Angelo Cpp)
April 24, 2010, 9:29am
2
mithereal
(Mithereal)
April 25, 2010, 7:18am
3
i tried like this
view.php
<?php $test=Games::model()->listAvailablegames();
var_dump($test->getAttributes($names=null));?>:</b>
and i get the following error
Call to a member function getAttributes() on a non-object
$test is an array of objects like
$test=>0=>object…
$test=>1=>object…
$test=>2=>object…
i tried this ar_dump($test->getAttributes($test));
same error
Vince
(Vadimg88)
April 25, 2010, 7:42am
4
Should be:
$attributes = Games::model()->getAttributes();
mithereal
(Mithereal)
April 25, 2010, 8:12am
5
when i use that it returns an empty array of indexes, the function called listAvailablegames(); generates the correct objects in the arraY,i guess im missing something here,
the objects generated look like.
my intention is to list all available game names that match users current state_code in a dropdown.
i cant really do $test->0->name, im just confused to what getatributes call actually is, do i need to pass it the data array %test or do i loop over it and pass the objects in the array keys?
array
0 =>
object(Games)[76]
private '_md' =>
object(CActiveRecordMetaData)[53]
public 'tableSchema' =>
object(CMysqlTableSchema)[55]
...
public 'columns' =>
array
...
public 'relations' =>
array
...
public 'attributeDefaults' =>
array
...
private '_model' =>
object(Games)[52]
...
private '_new' => boolean false
private '_attributes' =>
array
'id' => string '1' (length=1)
'name' => string 'Test game' (length=9)
'numbers' => string '0' (length=1)
'schedule_id' => string '6' (length=1)
'state_code' => string 'AZ' (length=2)
'time' => string '00:00:00' (length=<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' />
private '_related' =>
array
empty
private '_c' => null
private '_pk' => string '1' (length=1)
private '_errors' =>
array
empty
private '_validators' => null
private '_scenario' => string 'update' (length=6)
private '_e' => null
private '_m' => null
Vince
(Vadimg88)
April 25, 2010, 8:50am
6
Well according to the documentation you can’t get the attributes of an AR object from a CActiveDataProvider object.
What you can do is to build the cdbcriteria and then with the returned results construct a cactivedataprovider object.