Skip to content

動態模型

動態模型引擎是 Doggy 低程式碼平台的核心,透過 @Ef 註解搭配 PHP 8 Attributes 標記業務欄位,自動產生資料庫遷移、API 和管理介面。

概述

動態模型系統基於兩個核心註解建置:

  • Ef:標記業務欄位的分組和中繼資料屬性
  • EfGroup:定義欄位分組

註解定義在 src/Annotation/Ef.phpsrc/Annotation/EfGroup.php

php
// src/Annotation/Ef.php
class Ef
{
    public $value = [];

    public function __construct(array $data)
    {
        $this->value['group'] = $data['group'] ?? null;
        $this->value['bf'] = $data['isBF'] ?? false;
    }
}

定義模型

php
namespace App\Entity\Organization;

use App\Annotation\Ef;
use App\Entity\Traits\CommonTrait;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Table(name: 'org_department')]
class Department
{
    use CommonTrait;

    #[ORM\Id]
    #[ORM\Column(type: 'uuid', unique: true)]
    #[ORM\GeneratedValue(strategy: 'CUSTOM')]
    #[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
    private $id;

    #[Ef(displayName: '部门名称', required: true)]
    #[ORM\Column(length: 100)]
    private string $name;

    #[Ef(displayName: '部门编码', searchable: true)]
    #[ORM\Column(length: 50, nullable: true)]
    private ?string $code = null;
}

實體管理

在管理後台 低程式碼平台 → 實體管理App\Controller\Admin\Platform\EntityController)中可檢視和管理實體:

主要實體目錄

目錄實體說明
Entity/Organization/Department, Company, Corporation, Employee, Position, PositionLevel組織架構與員工
Entity/Platform/Entity, EntityProperty, View, ViewField, DataGrid, Menu, DataSource低程式碼引擎
Entity/Security/PasswordPolicy, PasswordStrengthRule, PasswordResetMethod, WebauthnCredential安全體系
Entity/Storage/File, StorageConfig, UploadSession檔案儲存
Entity/System/AuditLog, Task, TaskLog, EmailConfig, EmailTemplate, EmailLog, SystemCalendarEvent基礎設施

CommonTrait

所有實體透過 CommonTraitsrc/Entity/CommonTrait.php)組合以下能力:

php
trait CommonTrait
{
    use SoftDeleteableEntity;    // 软删除(deletedAt 字段)
    use TimestampableEntity;     // 时间戳(createdAt, updatedAt)
    use BlameableEntity;        // 操作人(createdBy, updatedBy)

    #[ORM\ManyToOne(targetEntity: Corporation::class)]
    private $corporation;

    #[ORM\ManyToOne(targetEntity: Company::class)]
    private $company;
}

自動產生

定義模型後,EfInitEntityCommand 等命令自動處理:

  • 資料庫遷移檔案產生
  • CRUD 介面渲染
  • 資料驗證規則
  • 權限檢查

管理後台

進入 低程式碼平台 → 實體管理/admin/platform/entity)可進行視覺化操作:

  • 實體屬性編輯(EntityProperty)
  • 屬性分組管理(EntityPropertyGroup)
  • 一鍵產生遷移
  • 關聯關係設定

基於 MIT 協議開源 | Copyright © 2026 Doggy