Download the PHP package vitalyspirin/yii2-simpleactiverecord without Composer

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

SimpleActiveRecord

Extension of Yii 2 ActiveRecord with automatically generated validators.

Quick Start

To install it you can just download zip or use composer:

To use it in code:

There is no need to overload rules() function to specify validators. Validators will be added automatically by class constructor based on table schema. However in current version relations (based on foreign keys) will not be added.

There are two ways to create an instance of such class. Constructor of SimpleActiveRecord takes one boolean parameter: $maximumValidation. If it's 'false' then only those validators will be added that are generated by Gii. In terms of above example it will look like this:

If to pass 'true' (which is also default) then maximum validation functionality will be added. It includes ranges for integer, ranges for enum, pattern for time etc. Of course you can see those validators:

If table schema changed then validators will be adjusted automatically.

Examples

Let's say we have the following SQL schema:

then if we run the following code:

we will get the following output:

Above validators are the same that would be generated by Gii module of Yii. Additional validators can be generated if to call class constructor without false parameter:

In this case the output will be the following (pay attention to 'person_gender', 'person_dob' and 'person_salary' fields):

array (size=5)
  0 => 
    array (size=2)
      0 => 
        array (size=2)
          0 => string 'person_firstname' (length=16)
          1 => string 'person_lastname' (length=15)
      1 => string 'required' (length=8)
  1 => 
    array (size=3)
      0 => 
        array (size=1)
          0 => string 'person_gender' (length=13)
      1 => string 'in' (length=2)
      'range' => 
        array (size=2)
          0 => string 'male' (length=4)
          1 => string 'female' (length=6)
  2 => 
    array (size=5)
      0 => 
        array (size=1)
          0 => string 'person_dob' (length=10)
      1 => string 'date' (length=4)
      'format' => string 'yyyy-MM-dd' (length=10)
      'min' => string '1000-01-01' (length=10)
      'max' => string '9999-12-31' (length=10)
  3 => 
    array (size=3)
      0 => 
        array (size=1)
          0 => string 'person_salary' (length=13)
      1 => string 'number' (length=6)
      'min' => int 0
  4 => 
    array (size=3)
      0 => 
        array (size=2)
          0 => string 'person_firstname' (length=16)
          1 => string 'person_lastname' (length=15)
      1 => string 'string' (length=6)
      'max' => int 35

You can also pass properties to contructor:

In the case above maximum validation will be chosen by default. You can specify validation level explicitly (Gii style validation in the example below):

Additional features

This extension of Active Record has also function getEnumValues() that shows enum values for table column. The following code

will return

You can also see tests in SimpleActiveRecordTest.php for simple examples.


All versions of yii2-simpleactiverecord with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
yidas/yii2-composer-bower-skip Version ~2.0.0
yiisoft/yii2 Version >=2.0.5
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 vitalyspirin/yii2-simpleactiverecord contains the following files

Loading the files please wait ....