2
如何使用變量作爲新屬性爲對象提供新屬性?從另一個對象分配一個對象屬性
下給我所需要的屬性對象:
switch ($property['property_type']):
case 'Residential':
$property = $this->property
->join('residential', 'property.id', '=','residential.property_id')
->join('vetting', 'property.id', '=', 'vetting.property_id')
->where('property.id', $id)
->first();
$property['id'] = $id;
break;
default:
return Redirect::route('property.index');
break;
endswitch;
下面給我的屬性和值的列表:
$numeric_features = App::make('AttributesController')->getAttributesByType(2);
這裏的問題是,如何動態地添加各$numeric_features
屬性對象?
foreach ($numeric_features as $numeric_feature) {
***$this->property->{{$numeric_feature->name}}***=$numeric_feature->value;
}
'$ property ['id'] = $ id;'這是一個數組嗎?以及'$ numeric_features'如何組織?鍵值對象?陣列? – Webinan
@ Webinan不,它們都是對象,它們都具有雄辯的db查詢的結果。 –