vigihdev/yii2-bridge-active-record
Composer 安装命令:
composer require vigihdev/yii2-bridge-active-record
包简介
Enhanced Active Record bridge for Yii2 with service container integration, validation, caching, and multilingual support
README 文档
README
Enhanced Active Record bridge for modern PHP applications, integrating a powerful service container, advanced validation, caching, and multilingual support. This library provides a flexible and robust ORM layer, designed to be easily integrated into any project requiring a solid data persistence solution.
Features
- Service Container Integration: Decouples database connections, making your models more portable and testable.
- Modern Validation: Leverages
yiisoft/validatorfor powerful and flexible validation rules (viavigihdev/yii2-bridge-validator). - Event-Driven Architecture: Dispatch events on
AfterInsert,AfterUpdate, andAfterDeleteto hook into the model lifecycle. - Seamless Relations: Easily define and query relationships between your entities.
- Modern Data Types: Automatic handling of
DateTimeImmutablefor date/time fields.
Installation
Install the package via Composer:
composer require vigihdev/yii2-bridge-active-record
Basic Usage
First, ensure your service container is configured to provide database connections. This library relies on vigihdev/yii2-bridge-db for connection management.
1. Create a Base Model
Create your own base model that extends VigihDev\Yii2Bridge\ActiveRecord\BaseActiveRecord and specifies the database service name.
<?php namespace App\Models; use VigihDev\Yii2Bridge\ActiveRecord\BaseActiveRecord; abstract class YourBaseModel extends BaseActiveRecord { protected static function getServiceName(): string { // The name of the database connection service configured in your container return 'db'; } }
2. Define an Entity
Create an entity class that represents a database table.
<?php namespace App\Models; use Yiisoft\ActiveRecord\ActiveQuery; /** * @property int $id * @property string $username * @property string $email * * @property UserProfile $profile */ class User extends YourBaseModel { public function tableName(): string { return '{{%user}}'; } public function getProfile(): ActiveQuery { return $this->hasOne(UserProfile::class, ['user_id' => 'id']); } }
3. Querying Data
You can now use the powerful query builder to fetch data.
// Find all users $users = User::query()->all(); // Find a single user by primary key $user = User::query()->where(['id' => 1])->one(); // Eager load relations $usersWithProfiles = User::query()->with('profile')->all(); // Access related data $username = $usersWithProfiles[0]->profile->full_name;
Testing
To run the test suite, use the following command:
./vendor/bin/phpunit
License
This project is licensed under the MIT License. See the LICENSE.md file for details.
vigihdev/yii2-bridge-active-record 适用场景与选型建议
vigihdev/yii2-bridge-active-record 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「orm」 「translation」 「validation」 「caching」 「active-record」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 vigihdev/yii2-bridge-active-record 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vigihdev/yii2-bridge-active-record 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 vigihdev/yii2-bridge-active-record 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kinikit - PHP Application development framework MVC component
A custom URL rule class for Yii 2 which allows to create translated URL rules
PHP Database ORM for Symfony1. Do NOT use for new projects: please move to a newest Symfony release and Doctrine2
A Laravel Eloquent model trait for translatable resource
Bureaux A Partager Edit - Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js
Adds request-parameter validation to the SLIM 3.x PHP framework
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-01