在Yii2中加载类属性

时间:2014-12-25 12:27:22

标签: yii2

例如,我有以下类:

class A extends yii\base\Model {
    public $attr1;
    public $attr2;
}

class B extends yii\db\ActiveRecord {
    ... some attributes in table including attr1 and attr2 ...
}

将值()从对象B加载到对象A而不是

是更优雅的方式
$objectA = new A();
$objectB = new B();
... obtaining values for $objectB ...
$objectA->load([StringHelper::basename($objectB->className()) => $objectB->attributes])

1 个答案:

答案 0 :(得分:0)

你可以做一个

$objectA->attributes = $objectB->attributes;