Home Backend Development PHP Tutorial Yii2 ActiveRecord adds additional properties

Yii2 ActiveRecord adds additional properties

Jul 29, 2016 am 09:06 AM
activerecord attributes sync

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.

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1266
29
C# Tutorial
1239
24
What is PHP-Activerecord framework? What is PHP-Activerecord framework? Jun 05, 2023 am 08:51 AM

The PHP-Activerecord framework is a lightweight ORM (Object Relational Mapping) framework that can map tables in the database to PHP objects, allowing developers to use an object-oriented approach to operate the database without writing complex SQL statements. . It originates from the ActiveRecord pattern in the Ruby on Rails framework, and the PHP-Activerecord framework is its implementation in the PHP language. The main idea of ​​this framework is to combine the data in the database with

How to use Attributes to manage code annotations in PHP8? How to use Attributes to manage code annotations in PHP8? Oct 18, 2023 am 09:48 AM

How to use Attributes to manage code annotations in PHP8? With the release of PHP8, an exciting new feature was introduced, namely Attributes. Attributes is a method of code annotation that allows us to add metadata to classes, methods, and attributes in a structured way. In this article, we will explore how to use Attributes to manage code annotations in PHP8 and provide some specific code examples. 1. What is Attrib?

How to use Attributes to add custom annotations to classes in PHP8? How to use Attributes to add custom annotations to classes in PHP8? Oct 18, 2023 am 10:16 AM

How to use Attributes to add custom annotations to classes in PHP8? Custom annotations are a way to add metadata to a class or method, which can help us obtain and process additional information on a specific class or method at runtime. In PHP8, the concept of Attributes was introduced, which allows us to easily add custom annotations to classes. This article will introduce how to use Attributes to implement custom annotations for classes in PHP8 and provide specific code examples. In PHP8, since

What is the sync package in Go language? What is the sync package in Go language? Jun 09, 2023 pm 10:43 PM

The sync package in the Go language is an important synchronization primitive library. It provides some basic synchronization primitives for coordinating threads' concurrent access to shared resources to avoid race conditions and data competition. In multi-threaded programming, synchronization is a critical task because many threads may modify the same shared resources at the same time, which can cause data inconsistency and program crashes. To this end, locks and other synchronization primitives need to be used to coordinate access between threads to ensure data correctness and consistency. Synchronization primitives provided in the sync package

Master the sync.WaitGroup function in the Go language documentation to implement concurrency control Master the sync.WaitGroup function in the Go language documentation to implement concurrency control Nov 03, 2023 pm 08:05 PM

Mastering the sync.WaitGroup function in the Go language documentation to implement concurrency control requires specific code examples. It is very important to implement concurrency control in the Go language, and the WaitGroup function in the sync package provides a simple and effective method to implement concurrency control. . This article will introduce in detail how to use the sync.WaitGroup function and provide specific code examples. In concurrent programming, it is often necessary to wait for all goroutines to complete before continuing to execute subsequent code.

How to extend the functionality of classes through Attributes in PHP8? How to extend the functionality of classes through Attributes in PHP8? Oct 25, 2023 am 11:54 AM

How to extend the functionality of classes through Attributes in PHP8? In PHP8, a new feature was introduced - Attributes, also known as attributes. It can add metadata to entities such as classes, class properties, methods, and functions, and these metadata can be accessed and used at runtime. Attributes provide a concise and flexible way to extend the functionality of classes and help developers better organize and understand code. In order to better understand and apply Attributes, the following

How to use Attributes to extend the functionality of a class in PHP8? How to use Attributes to extend the functionality of a class in PHP8? Oct 19, 2023 am 09:13 AM

How to use Attributes to extend the functionality of a class in PHP8? With the release of PHP8, new language features Attributes were introduced. Attributes is a feature that adds metadata in the form of annotations in the code. By using Attributes, we can add additional information to elements such as classes, methods, properties, etc. to meet more complex business requirements and development specifications. In this article, we will detail using the Attributes extension in PHP8

How to manage code metadata through PHP8's Attributes? How to manage code metadata through PHP8's Attributes? Oct 20, 2023 pm 07:12 PM

How to manage code metadata through PHP8's Attributes? With the release of PHP8, Attributes have become a new feature in PHP development. Attributes are used to associate metadata with code, thereby adding more contextual information and annotations to the code. By using Attributes, developers can better manage code metadata and provide a more flexible and readable structure for the code. In PHP8, Attributes are passed in the class

See all articles