yiisoft/active-record
Composer 安装命令:
composer require yiisoft/active-record
包简介
Active record pattern implementation
关键字:
README 文档
README
Yii Active Record
This package provides Active Record pattern implementation.
Supported databases:
| Packages | Build status |
|---|---|
| Microsft SQL Server | |
| MySQL | |
| Oracle | |
| PostgreSQL | |
| SQLite |
Requirements
- PHP 8.1 - 8.5.
Package dependencies installed automatically.
- yiisoft/db:
^2.0— Yii Database Library
Some features require additional packages.
- yiisoft/arrays:
For \Yiisoft\Arrays\ArrayableInterface support— Yii Array Helper - yiisoft/db-sqlite:
For SQLite database support— SQLite driver for Yii Database - yiisoft/db-mysql:
For MySQL database support— MySQL and MariaDB driver for Yii Database - yiisoft/db-pgsql:
For PostgreSQL database support— PostgreSQL driver for Yii Database - yiisoft/db-mssql:
For MSSQL database support— Microsoft SQL Server driver for Yii Database - yiisoft/db-oracle:
For Oracle database support— Oracle driver for Yii Database - yiisoft/factory:
For factory support— Object factory that is able to resolve dependencies from PSR-11 container - yiisoft/event-dispatcher:
For events support— PSR-14 event dispatcher
Installation
The package could be installed with Composer:
composer require yiisoft/active-record
Important
See also installation notes for yiisoft/db
package.
After installing yiisoft/active-record, you also need to configure a database connection:
- Configure the connection, follow Yii Database guide.
- Define the Database Connection for Active Record
General usage
Defined your active record class (for more information, follow Create Active Record Model guide):
final class User extends \Yiisoft\ActiveRecord\ActiveRecord { public int $id; public string $username; public string $email; public string $status = 'active'; public function tableName(): string { return '{{%user}}'; } }
For fast prototyping you can use dynamic properties by adding #[\AllowDynamicProperties] attribute:
/** * Database fields: * @property int $id * @property string $username * @property string $email * @property string $status **/ #[\AllowDynamicProperties] final class User extends \Yiisoft\ActiveRecord\ActiveRecord { }
Now you can use the active record:
// Creating a new record $user = new User(); $user->username = 'alexander-pushkin'; $user->email = 'pushkin@example.com'; $user->save(); // Retrieving a record $user = User::query()->findByPk(1); // Read properties $username = $user->username; $email = $user->email;
Documentation
- Define the Database Connection for Active Record
- Create Active Record Model
- Define Active Record Relations
- Extending Functionality With Traits
- Using Dependency Injection With Active Record Model
- Optimistic Locking
- Internals
If you need help or have a question, the Yii Forum is a good place for that. You may also check out other Yii Community Resources.
License
The Yii Active Record is free software. It is released under the terms of the BSD License.
Please see LICENSE for more information.
Maintained by Yii Software.
Support the project
Follow updates
yiisoft/active-record 适用场景与选型建议
yiisoft/active-record 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 93.87k 次下载、GitHub Stars 达 119, 最近一次更新时间为 2018 年 08 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Active Record」 「yii」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 yiisoft/active-record 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yiisoft/active-record 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 yiisoft/active-record 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Propel2 is an open-source Object-Relational Mapping (ORM) for PHP 5.5 and up.
PHP Interface for Babel Street Text Analytics
A Symfony extension to get active class base on current bundle/controller/action
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
LDAP user provider bundle for Symfony 6.4
The helper class for Laravel applications to get active class base on current route for Laravel 11
统计信息
- 总下载量: 93.87k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 121
- 点击次数: 14
- 依赖项目数: 27
- 推荐数: 4
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2018-08-20