Download the PHP package spinitron/yii2-dynamic-ar without Composer

On this page you can find all versions of the php package spinitron/yii2-dynamic-ar. 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 yii2-dynamic-ar

Dynamic Active Record

The yii2-dynamic-ar extension adds NoSQL-like documents to Yii 2 Framework's Active Record ORM.

Maria Dynamic Columns and PostgreSQL jsonb

Dynamic Columns in Maria 10.0+ and jsonb column types and functions in in PostgreSQL 9.4+ provide, in effect, a NoSQL document attached to every row of an SQL table. It's a powerful feature that allows you to do things that have been hard in relational DBs. Problems that might drive you to Couch or Mongo, or to commit a crime like EAV to your schema, can suddenly be easy when

Dynamic AR works for Maria now and will come to PostgreSQL in the future.

Example

An online shopping site has a table that stores info about each product.

In this (simplistic) example, details will hold the Maria Dynamic Column blob and is declared in the model class by the dynamicColumn() method. Everything else in a Dynamic AR class declaration is familiar AR stuff.

Now we can do all the normal AR things with Product but in addition we can read, write and update attributes not mentioned in the schema.

Think of the details table column as holding a serialized associative array. But unlike saving a JSON document in a text field, you can use dynamic attributes anywhere in your code, including in queries, just as you do with schema attributes. The differences are

For example

The dot notation works anywhere Yii accepts an attribute name string, for example

Design principle

DynamicActiveRecord adds a fourth to the three things that reading and writing AR model properties can do:

  1. $model->foo accesses, if it exists, the instance variable $foo,
  2. otherwise it accesses the column attribute foo, if the model's table has a column "foo",
  3. otherwise it accesses the virtual attribute foo, if the model's class has magic getFoo() / setFoo() methods,
  4. else $model->foo accesses a dynamic attribute named "foo".

So any attribute name that doesn't refer to one of the normal 3 kinds of AR model property (instance variable, column attribute, virtual attribute) is automatically a dynamic property as soon as you use it. There is no way to declare a dynamic property and you can only define one by writing to it.

And reading an attribute that doesn't exist returns null.

PHP null, SQL NULL and Maria

Maria does not encode a dynamic column set to SQL NULL:

Thus if a table record currently has a dynamic column 'b' and Maria executes an update setting it to NULL then Maria removes 'b' from the record. (This makes sense if NULL has its conventional database meaning of 'data value does not exist.') So DynamicActiveRecord cannot possibly distinguish a NULL value from a dynamic column that doesn't exist after reading back from the DB.

In order to be consistent, DynamicActiveRecord always returns null when you read a dynamic attribute that hasn't been set, in contrast to ActiveRecord which throws an exception. But it also makes sense if null means 'does not exist' and given the design principle (above).

Further reading

Class reference

More documentation

Useful links

Regenerate docs in gh-pages branch

vendor/bin/apidoc api . . --template="spinitron\dynamicAr\doc\template\ApiRenderer"

Questions, comments, issues

Use the issue tracker. Or you can easily find my email if you prefer.


Copyright (c) 2015 Spinitron LLC


All versions of yii2-dynamic-ar with dependencies

PHP Build Version
Package Version
Requires yiisoft/yii2 Version ~2.0
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 spinitron/yii2-dynamic-ar contains the following files

Loading the files please wait ....