PHPackages                             vitalyspirin/yii2-simpleactiverecord - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. vitalyspirin/yii2-simpleactiverecord

ActiveYii2-extension

vitalyspirin/yii2-simpleactiverecord
====================================

Extension of Yii2 ActiveRecord with added automatically generaged validators

1.0.7(7y ago)0966HTMLPHP &gt;=5.4.0

Since Sep 6Pushed 7y ago1 watchersCompare

[ Source](https://github.com/vitalyspirin/yii2-simpleactiverecord)[ Packagist](https://packagist.org/packages/vitalyspirin/yii2-simpleactiverecord)[ Docs](https://github.com/vitalyspirin/yii2-simpleactiverecord)[ RSS](/packages/vitalyspirin-yii2-simpleactiverecord/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (8)Dependencies (6)Versions (9)Used By (0)

SimpleActiveRecord
==================

[](#simpleactiverecord)

Extension of Yii 2 ActiveRecord with automatically generated validators.

Quick Start
-----------

[](#quick-start)

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

```
composer require vitalyspirin/yii2-simpleactiverecord

```

To use it in code:

```
use vitalyspirin\yii2\simpleactiverecord\SimpleActiveRecord;

class T1 extends SimpleActiveRecord
{

}
```

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:

```
$t1 = new T1(false);
```

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:

```
$t1 = new T1();
var_dump($t1->rules());
```

If table schema changed then validators will be adjusted automatically.

Examples
--------

[](#examples)

Let's say we have the following SQL schema:

```
CREATE TABLE person
(
  person_id         INT PRIMARY KEY AUTO_INCREMENT,
  person_firstname  VARCHAR(35) NOT NULL,
  person_lastname   VARCHAR(35) NOT NULL,
  person_gender     ENUM('male', 'female'),
  person_dob        DATE NULL,
  person_salary     DECIMAL UNSIGNED
);
```

then if we run the following code:

```
use vitalyspirin\yii2\simpleactiverecord\SimpleActiveRecord;

class Person extends SimpleActiveRecord
{
    // totally empty class
}

$person = new Person(false  /*Gii style validation only*/ );
var_dump($person->rules());
```

we will get the following output:

```
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=2)
      0 =>
        array (size=1)
          0 => string 'person_salary' (length=13)
      1 => string 'number' (length=6)
  2 =>
    array (size=2)
      0 =>
        array (size=1)
          0 => string 'person_dob' (length=10)
      1 => string 'safe' (length=4)
  3 =>
    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
  4 =>
    array (size=2)
      0 =>
        array (size=1)
          0 => string 'person_gender' (length=13)
      1 => string 'string' (length=6)

```

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:

```
$person = new Person();
var_dump($person->rules());
```

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:

```
$person = new Person(['person_firstname' => 'John', 'person_lastname' => 'Smith']);
echo $person->person_firstname;
```

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

```
$person = new Person(false, ['person_firstname' => 'John', 'person_lastname' => 'Smith']);
echo $person->person_firstname;
```

Additional features
-------------------

[](#additional-features)

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

```
$person = new Person();
var_dump($person->getEnumValues());
```

will return

```
array (size=1)
  'person_gender' =>
    array (size=2)
      0 => string 'male' (length=4)
      1 => string 'female' (length=6)

```

You can also see tests in [SimpleActiveRecordTest.php](tests/unit/SimpleActiveRecordTest.php) for simple examples.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~105 days

Recently: every ~87 days

Total

8

Last Release

2799d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/402aacecdf4a5524cb6506fa9d8c332891936d011edb603650c72c73dbb4d930?d=identicon)[vitalyspirin](/maintainers/vitalyspirin)

---

Top Contributors

[![vitalyspirin](https://avatars.githubusercontent.com/u/7786743?v=4)](https://github.com/vitalyspirin "vitalyspirin (80 commits)")

---

Tags

active-recordactiverecordsimpleactiverecordsimple active record

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/vitalyspirin-yii2-simpleactiverecord/health.svg)

```
[![Health](https://phpackages.com/badges/vitalyspirin-yii2-simpleactiverecord/health.svg)](https://phpackages.com/packages/vitalyspirin-yii2-simpleactiverecord)
```

###  Alternatives

[yiisoft/yii2-redis

Redis Cache, Session and ActiveRecord for the Yii framework

48011.7M245](/packages/yiisoft-yii2-redis)[yiisoft/yii2-elasticsearch

Elasticsearch integration and ActiveRecord for the Yii framework

4371.9M15](/packages/yiisoft-yii2-elasticsearch)[yiisoft/yii2-mongodb

MongoDB extension for the Yii framework

3312.1M45](/packages/yiisoft-yii2-mongodb)[yiisoft/yii2-sphinx

Sphinx full text search engine extension for the Yii framework

180997.7k5](/packages/yiisoft-yii2-sphinx)[nickcv/yii2-encrypter

Openssl Encrypter for Yii2

19640.0k1](/packages/nickcv-yii2-encrypter)[cycle/active-record

Provides a simple way to work with your database using Active Record pattern and Cycle ORM

671.3k3](/packages/cycle-active-record)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
