Home >Backend Development >PHP Tutorial >Yii2 ActiveRecord adds additional properties

Yii2 ActiveRecord adds additional properties

WBOY
WBOYOriginal
2016-07-29 09:06:141888browse

If some of the attributes in your Form are not in the database, and your Mode integrates ActiveRecord, you can rewrite those attributes that are not defined in the database through $model->load(). attributes() function, for example:

/**
	 *
	 * {@inheritDoc}
	 *
	 * @see \common\db\ActiveRecord::attributes()
	 */
	public function attributes ()
	{
		$attributes = parent::attributes();
		$attributes[] = 'sync_take_rate';
		$attributes[] = 'sync_show_virtual';
		return $attributes;
	}

Then setting labels and hints in attributeLabels() and attributeHints() is the same as writing other attributes.

The above introduces Yii2 ActiveRecord to add additional attributes, including aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn