Yii2 ActiveRecord adds additional properties

WBOY
Release: 2016-07-29 09:06:14
Original
1864 people have browsed it

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;
	}
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!