PHP code example of vitalyspirin / yii2-simpleactiverecord

1. Go to this page and download the library: Download vitalyspirin/yii2-simpleactiverecord library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vitalyspirin / yii2-simpleactiverecord example snippets


use vitalyspirin\yii2\simpleactiverecord\SimpleActiveRecord;


class T1 extends SimpleActiveRecord
{
    
}

$t1 = new T1(false);

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

use vitalyspirin\yii2\simpleactiverecord\SimpleActiveRecord;


class Person extends SimpleActiveRecord
{
    // totally empty class
}

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

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

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

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

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

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 'ay (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)

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