0
嘗試將我的CRM系統的屬性添加到我的AR模型中。yii2在運行時添加屬性
public function getCustomFields($key = null)
{
if (static::$customFields === null)
{
$fields = (new Query)->from('client_fields')->indexBy('key')->all(static::$conn);
if ($columns = static::$conn->getSchema()->getTableSchema('client_profiles')->getColumnNames())
{
foreach ($columns as $column)
{
if (isset($fields[$column]))
{
static::$customFields[$column]['name'] = $fields[$column]['name'];
static::$customFields[$column]['settings'] = @json_decode($fields[$column]['settings'], true);
}
if(! isset($this->{$column}))
{
$this->{$column} = null;
}
}
}
static::$customFields = static::$customFields ?: [];
}
return $key ? (isset(static::$customFields[$key]) ? static::$customFields[$key] : null) : static::$customFields;
}
這裏是結果:
Setting unknown property: common\modules\crm\models\CrmClient::user_id
等待最佳的解決方案來解決這個問題...