例如,我有以下类:
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])
答案 0 :(得分:0)
你可以做一个
$objectA->attributes = $objectB->attributes;