php - Can the objects detected by Yii2 AR be accessed using array mode? ?
给我你的怀抱
给我你的怀抱 2017-06-23 09:11:24
0
1
725

$infoModel = InfoModel::findOne(1);
The above is to find the data with id 1. I have printed $infoModel, which is an object.
However, the correct data can be printed successfully by outputting the following two sentences:

echo $infoModel -> name; //这个可以理解   他是对象可以->
echo $infoModel['name']; //这个不理解  他不是数组啊

The following is the printed $infoModel:

app\models\InfoModel Object
(
    [_attributes:yii\db\BaseActiveRecord:private] => Array
        (
            [id] => 1
            [name] => 我问问2
            [age] => 32
        )

    [_oldAttributes:yii\db\BaseActiveRecord:private] => Array
        (
            [id] => 1
            [name] => 我问问2
            [age] => 32
        )

    [_related:yii\db\BaseActiveRecord:private] => Array
        (
        )

    [_errors:yii\base\Model:private] => 
    [_validators:yii\base\Model:private] => 
    [_scenario:yii\base\Model:private] => default
    [_events:yii\base\Component:private] => Array
        (
        )

    [_behaviors:yii\base\Component:private] => Array
        (
        )

)

Also, by the way<?php echo $form -> field($infoModel,'name')->textInput(array('value' => $infoModel['name'])); ?>
Is the first parameter $infoModel of the field here necessarily a model object? I tried to convert $infoModel into an array in the controller and an error occurred? ? ?

给我你的怀抱
给我你的怀抱

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!