Reputation: 9
i have a problem using active record in Yii2. When i do:
$x = Model::find()->all();
What i expected the value of $x will be:
array(2) {
[0] => array(2) {
['col1'] => string(3) "xxx2"
['col2'] => string(3) "xxx3"
}
[1] => {
['col1'] => string(3) "xxx2"
['col2'] => string(3) "xxx3"
}
}
What i got with $x were:
array(2) {
[0]=> object(app\models\X)#77 (13) {
['col1'] => string(3) "xxx2"
['col2'] => string(3) "xxx3"
["_attributes":"yii\db\BaseActiveRecord":private]=> array(5) {
['col1'] => string(3) "xxx2"
['col2'] => string(3) "xxx3"
}
["_oldAttributes":"yii\db\BaseActiveRecord":private]=> array(5) {
['col1'] => string(3) "xxx2"
['col2'] => string(3) "xxx3"
}
["_related":"yii\db\BaseActiveRecord":private]=> array(0) { }
["_errors":"yii\base\Model":private]=> NULL
["_validators":"yii\base\Model":private]=> NULL
["_scenario":"yii\base\Model":private]=> string(7) "default"
["_events":"yii\base\Component":private]=> array(0) { }
["_behaviors":"yii\base\Component":private]=> array(0) { }
}
[1]=> object(app\models\X)#77 (13) {
['col1'] => string(3) "xxx2"
['col2'] => string(3) "xxx3"
["_attributes":"yii\db\BaseActiveRecord":private]=> array(5) {
['col1'] => string(3) "xxx2"
['col2'] => string(3) "xxx3"
}
["_oldAttributes":"yii\db\BaseActiveRecord":private]=> array(5) {
['col1'] => string(3) "xxx2"
['col2'] => string(3) "xxx3"
}
["_related":"yii\db\BaseActiveRecord":private]=> array(0) { }
["_errors":"yii\base\Model":private]=> NULL
["_validators":"yii\base\Model":private]=> NULL
["_scenario":"yii\base\Model":private]=> string(7) "default"
["_events":"yii\base\Component":private]=> array(0) { }
["_behaviors":"yii\base\Component":private]=> array(0) { }
}
}
The question is, how to make the $x's value just like what i expected. I use Yii2 basic. Thanks guys, i appreciate your help.
Upvotes: 0
Views: 1130