我想知道是否有办法只获取属性名称?在示例中,我的意思是:id, name, user。我不需要值,只需要属性名称。
app\models\Data Object
(
[_attributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 1
[name] =>
[user] =>
)
[_oldAttributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 1
[name] =>
[user] =>
)
)
Run Code Online (Sandbox Code Playgroud)
谢谢!
你可以像注释中的代码那样做,但 Yii 也提供了一个函数ActiveRecord来获取属性名称:
$model->attributes();
Run Code Online (Sandbox Code Playgroud)
官方文档:http ://www.yiiframework.com/doc-2.0/yii-db-activerecord.html#attributes() -detail