PHP code example of xakki / yii2-ar-json

1. Go to this page and download the library: Download xakki/yii2-ar-json 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/ */

    

xakki / yii2-ar-json example snippets


/**
 * Example class
 * @property integer $id
 * @property string $create
 * @property string $text
 * @property array $data
 */
class Example extends \xakki\yii2-ar-json\components\ActiveRecordJson
{
    protected $_json_attribute = 'option';
    protected $_json_catch = ['text', 'data', 'info'];

    public static function tableName()
    {
        return '{{example}}';
    }
    
    /**
    * For new record only
    */
    public function setAttributeDefault() {
        $this->text = 'Example text';
        $this->data = ['test'];
        $this->info = 2
    }
    
    public static function doSomeThing() {
        $thisData = self::findOne(1);
        echo $thisData->text;
        print_r($thisData->data);
    }
    
}