Download the PHP package yii2tech/ar-dynattribute without Composer

On this page you can find all versions of the php package yii2tech/ar-dynattribute. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package ar-dynattribute

ActiveRecord Dynamic Attribute Extension for Yii2


This extension provides dynamic ActiveRecord attributes stored into the single field in serialized state.

For license information check the LICENSE-file.

Latest Stable Version Total Downloads Build Status

Installation

The preferred way to install this extension is through composer.

Either run

or add

to the require section of your composer.json.

Usage

This extension provides dynamic ActiveRecord attributes stored into the single field in serialized state. For example: imagine we create a web site, where logged in user may customize its appearance, like changing color schema or enable/disable sidebar and so on. In order to make this customization persistent all user's choices should be stored into the database. In general each view setting should have its own column in the 'user' table. However, this is not very practical in case your application is under development and new settings appear rapidly. Thus it make sense to use single text field, which will store all chosen view parameters in the serialized string. If new option introduced there will no necessity to change 'user' table schema. Migration for the 'user' table creation may look like following:

Heads up! In general such data storage approach is a bad practice and is not recommended to be used. Its main drawback is inability to use dynamic attributes in condition for the search query. It is acceptable only for the attributes, which are directly set and read for single record only, and never used for the filter queries.

Tip: you may store dynamic attributes into 'JSON' type column instead of plain text, in case you are using modern DBMS with built-in JSON support (e.g. MySQL >= 5.5 or PostgreSQL), however, you will have to deal with possible search condition composition on your own - this extension does not provide explicit support for it.

This extension provides [[\yii2tech\ar\dynattribute\DynamicAttributeBehavior]] ActiveRecord behavior for the dynamic attributes support. For example:

Once being attached [[\yii2tech\ar\dynattribute\DynamicAttributeBehavior]] allows its owner to operate dynamic attributes just as regular one. On model save they will be serialized and stored into the holding field. After record is fetched from database the first attempt to read the dynamic attributes will unserialize them and prepare for the usage. For example:

You may use dynamic attributes as the regular ActiveRecord attributes. For example: you may specify the validation rules for them and obtain their values via web form.

Note: keep in mind that dynamic attributes do not correspond to ActiveRecord entity fields, thus some particular ActiveRecord methods like updateAttributes() will not work for them.

Default values setup

As you may note from above example, you can provide a default values for the dynamic attributes via [[\yii2tech\ar\dynattribute\DynamicAttributeBehavior::$dynamicAttributeDefaults]]. Thus once you need extra dynamic attribute for your model you can just update the dynamicAttributeDefaults list with corresponding value, without necessity to perform any updates on your database.

Note: you may exclude dynamic attribute, which value equals the default one, from saving disabling [[\yii2tech\ar\dynattribute\DynamicAttributeBehavior::$saveDynamicAttributeDefaults]] option.

Restrict dynamic attribute list

Setup of the dynamic attribute default values not only useful, but in general is necessary. This list puts a restriction on the possible dynamic attribute names. Only attributes, which have default value specified can be set or read from the model. This prevents the possible mistakes caused by typos in the code. For example:

However sometimes there is necessity of storage list of attributes, which can not be predicted. For example, saving response fields from some external service. In this case you can disable check performed on attribute setter using [[\yii2tech\ar\dynattribute\DynamicAttributeBehavior::$allowRandomDynamicAttribute]]. If it is set to true you will be able to setup any dynamic attribute no matter declared or not at dynamicAttributeDefaults.

Note: you can also use [[\yii2tech\ar\dynattribute\DynamicAttributeBehavior::setDynamicAttributes()]] method to bypass naming restriction. This method will set all provided attributes without any checks.

You can as well control the dynamic attributes list to be actually saved using [[\yii2tech\ar\dynattribute\DynamicAttributeBehavior::$dynamicAttributeSaveFilter]]. If set to true it will exclude any attribute, which is not listed at dynamicAttributeDefaults option. You may as well specify it as a PHP callback, which will perform some custom filtering. This option allows you to remove obsolete dynamic attributes, which existed in the past, but no longer actual.

Serializer setup

By default [[\yii2tech\ar\dynattribute\DynamicAttributeBehavior]] saves the dynamic attribute in JSON format. However, you may setup another serializer for them via [[\yii2tech\ar\dynattribute\DynamicAttributeBehavior::$serializer]]. The following serializers are available withing this extension:

Please refer to the particular serializer class for more details.


All versions of ar-dynattribute with dependencies

PHP Build Version
Package Version
Requires yiisoft/yii2 Version ~2.0.14
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package yii2tech/ar-dynattribute contains the following files

Loading the files please wait ....