davihu/phalcon-ext

Phalcon 框架的各种扩展和实用工具

v5.0.0 2022-04-12 10:29 UTC

This package is not auto-updated.

Last update: 2024-09-24 22:11:47 UTC


README

Phalcon 框架的各种扩展和实用工具

先决条件

  1. Phalcon 框架 2.x 或 3.x

安装

使用 Composer

您可以使用 composer 包管理器进行安装。运行以下命令之一:

$ php composer.phar require davihu/phalcon-ext "^1.2"

或者将以下内容添加到您的 composer.json 文件中:

"davihu/phalcon-ext": "^1.2"

新功能?

版本 1.2

添加嵌套集支持

为您的模型添加嵌套集支持。只需在模型中使用 trait \PhalconExt\Mvc\Model\Traits\NestedSetTrait 即可。

版本 1.1

添加 SQL 数据库迁移支持

可以轻松附加到您的控制台应用程序。

支持的命令
php console.php migrations generate                        # generates new migration class
php console.php migrations migrate                         # migrates database to last version
php console.php migrations migrate 160910160944            # migrates database to selected version
php console.php migrations sql > migrate.sql               # saves SQL statements for migration to last version to file migrate.sql
php console.php migrations sql 160910160944 > migrate.sql  # saves SQL statements for migration to selected version to file migrate.sql
在控制台引导文件中设置
  1. 选择迁移目录

    define('MIGRATIONS_DIR', '... your migrations dir ...');

  2. 将目录注册到您的加载器中

不使用命名空间

$loader->registerDirs([ ... , MIGRATIONS_DIR]);

使用命名空间

$loader->registerNamespaces([ ... , 'Your\\Namespace' => MIGRATIONS_DIR]);
  1. 将迁移服务注册到 DI 中

不使用命名空间

$di->set('migrations', function () {
    return new \PhalconExt\Db\SqlMigrations($this->get('db'), MIGRATIONS_DIR);
}, true);

使用命名空间

$di->set('migrations', function () {
    return new \PhalconExt\Db\SqlMigrations($this->get('db'), MIGRATIONS_DIR, 'Your\\Namespace');
}, true);
编写迁移类
use PhalconExt\Db\SqlMigrations\AbstractMigration;

class Migration160910160944 extends AbstractMigration
{
    public function up()
    {
        # simple statements
        $this->addSql("ALTER TABLE robots ADD COLUMN number VARCHAR(20)");

        # routine statements like triggers, procedures and functions
        $this->addSql("CREATE TRIGGER MyTrigger ...", true);
    }

    public function down()
    {
        $this->addSql("ALTER TABLE robots DROP COLUMN number");
        $this->addSql("DROP TRIGGER MyTrigger");
    }
}

就这样,非常简单但功能强大!

内容

数据库

模型

验证器

许可证

Phalcon Ext 是开源软件,许可协议为 新 BSD 许可证。© David Hübner