承接 sam-it/yii2-singletableinheritance 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sam-it/yii2-singletableinheritance

Composer 安装命令:

composer require sam-it/yii2-singletableinheritance

包简介

Single Table Inheritance for Yii2

README 文档

README

Scrutinizer Code Quality Code Coverage Continous integration Latest Stable Version Total Downloads License Monthly Downloads

Yii2 Single Table Inheritance (STI) using traits

The reason this is implemented as traits is to prevent developers from putting 3rd party classes in their class hierarchy. This implementation uses 2 traits, 1 for the query class and 1 for the model class.

The query trait adds a filter based on the model class configured for the query. It implements the prepare() function. In case you use this trait on a class that also implements the prepare() function you MUST manually call ours like this:

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);
    }
}

The model trait is a bit more complicated but still has a small surface of interaction with your code. It uses the init() function, so if you override that in the base STI class (the one where you use the trait) you must call our init function:

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

Configure your inheritance config by implementing a static function:

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'
            ]    
        ];       
    }
}

This function is only called once and its results are cached.

统计信息

  • 总下载量: 23.62k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-05-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固