PHP code example of sam-it / yii2-singletableinheritance

1. Go to this page and download the library: Download sam-it/yii2-singletableinheritance 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/ */

    

sam-it / yii2-singletableinheritance example snippets


class MyQuery extends \yii\db\ActiveQuery 
{
    use \SamIT\Yii2\SingleTableInheritance\SingleTableInheritanceQueryTrait;

    public function prepare($builder) 
    {
        // Your own code here
        $this->prepareSingleTableInheritance();
        // Your own code here
        return parent::prepare($builder);
    }
}

class Transport extends \yii\db\ActiveRecord 
{
    use \SamIT\Yii2\SingleTableInheritance\SingleTableInheritanceTrait;
    public function init(): void 
    {
        self::initSingleTableInheritance($this);
    } 
}

class Transport extends \yii\db\ActiveRecord 
{
    use \SamIT\Yii2\SingleTableInheritance\SingleTableInheritanceTrait;
    private static function inheritanceConfig(): array
    {
        return [
            'column' => 'type',
            'map' => [
                Car::class => 'car',
                Bike::class => 'bike'
            ]    
        ];       
    }
}