$infoModel = InfoModel::findOne(1);
上面就是查找id为1的数据,我打印过$infoModel,他是个对象
可是 输出以下2句都可以成功打印正确数据:
echo $infoModel -> name; //这个可以理解 他是对象可以->
echo $infoModel['name']; //这个不理解 他不是数组啊
以下是打印的$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
(
)
)
还有顺便问下<?php echo $form -> field($infoModel,'name')->textInput(array('value' => $infoModel['name'])); ?>
这里的field的第一个参数$infoModel是不是一定是模型对象,我试着在控制器把$infoModel转成数组就报错了???