yiisoft/active-record 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

yiisoft/active-record

最新稳定版本:1.1.0

Composer 安装命令:

composer require yiisoft/active-record

包简介

Active record pattern implementation

README 文档

README

Yii

Yii Active Record


Latest Stable Version Total Downloads Code Coverage Mutation testing badge Static analysis type-coverage psalm-level

This package provides Active Record pattern implementation.

Supported databases:

Packages Build status
Microsft SQL Server Build status
MySQL Build status
Oracle Build status
PostgreSQL Build status
SQLite Build status

Requirements

  • PHP 8.1 - 8.5.
Package dependencies installed automatically.
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:

  1. Configure the connection, follow Yii Database guide.
  2. 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

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

Open Collective

Follow updates

Official website Twitter Telegram Facebook Slack

统计信息

  • 总下载量: 88.41k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 120
  • 点击次数: 4
  • 依赖项目数: 24
  • 推荐数: 3

GitHub 信息

  • Stars: 118
  • Watchers: 21
  • Forks: 37
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2018-08-20