nullref / yii2-core
Requires
- php: >=5.4.0
- symfony/filesystem: ^3.1
- symfony/finder: ^3.1
- voskobovich/yii2-linker-behavior: dev-master
- yiisoft/yii2: >=2.0.6
Requires (Dev)
- yiisoft/yii2-gii: ^2.0@dev
This package is auto-updated.
Last update: 2024-08-29 03:47:21 UTC
README
工作进度
管理模块
安装
要安装此扩展,建议使用 composer。
可以运行
php composer.phar require --prefer-dist nullref/yii2-core "*"
或者添加
"nullref/yii2-core": "*"
到您的 composer.json
文件的 require 部分。
配置结构
此模块设计用于与特殊的配置文件一起工作。
当您使用 module/install
命令时,如果不存在,它将在配置文件夹中创建 installed_modules.php
文件。
此文件将包含已安装模块的配置数组(明显)。
您需要将此配置与您的应用程序配置(web、console 等)合并。
我建议使用以下结构,它用于我们的 应用程序模板。
- installed_modules.php
<?php return [];
- modules.php
<?php $config = require(__DIR__ . '/installed_modules.php'); return array_merge($config, []);
- web.php
<?php $modules = require(__DIR__ . '/modules.php'); $config = [ //... 'modules' => $modules, //... ]; return $config;
当您使用此配置结构时,您可以在 modules.php
中覆盖已安装模块的配置。
此外,可以将 modules.php
文件包含到 console.php
配置文件中。
特定于应用程序的配置可以直接添加到相应的配置文件中。
模块系统
此模块提供创建模块系统的基本工具。
可用模块
为了完全集成,您必须运行控制台命令
php yii module/install <module-name>
内容
基于 Yii2 的快速 Web 开发核心模块。此软件包包含
-
组件
- EntityManager - 用于简单管理实体的组件(模型)
-
接口
- IAdminModule - 可由 nullref\yii2-admin 使用的模块接口
- IRoleContainer - 提供角色的 RBAC 接口
- IEntityManager - EntityManager 接口
- IEntityManageble - 包含 EntityManager 的类的接口
翻译覆盖
核心包包含 PhpMessageSource 类,允许合并默认模块和应用程序的消息。例如,对于 admin 模块
[ /** App config **/ 'components' => [ 'i18n' => [ 'translations' => [ '*' => ['class' => 'yii\i18n\PhpMessageSource'], 'admin' => ['class' => 'nullref\core\components\i18n\PhpMessageSource'], ], ], ] ]
在这种情况下,应用程序目录中的 admin
类别的消息将与模块的默认消息合并。
模块迁移
模块包含 MigrateController
控制器,允许处理模块的迁移。
例如:
php yii core/module --moduleId=admin
-- 应用 admin
模块 ID 的迁移
请注意:迁移应该有命名空间
此外,可以处理所有模块的迁移
php yii core/module
-- 收集所有可能的迁移位置。
默认情况下,迁移在模块类的 migrations
目录中查找。
如果您想覆盖此行为,您可以通过模块类实现 IHasMigrateNamespace
接口。
EntityManager
用于处理具有软删除和分类的模型的组件。
配置
/** module config **/ 'productManager' => [ "class" => "nullref\\product\\components\\EntityManager", 'hasImage' => false, 'hasStatus' => false, 'model' => [ 'class' => 'app\\models\\Product', 'relations' => [ 'category' => 'nullref\\category\\behaviors\\HasCategory', 'vendor' => 'app\\behaviors\\HasVendor', ], ], 'searchModel' => 'app\\models\\ProductSearch', ], /** ... **/
可用方法
createModel()
- 创建新模型createSearchModel()
- 创建新搜索模型findOne($condition)
- 根据条件查找一个模型findAll($condition)
- 根据条件查找所有模型find($condition = [])
- 创建带有条件的ActiveQuerygetMap($index = 'id', $value = 'title', $condition = [], $asArray = true)
- 通过条件获取模型的键→值数组delete($model)
- 删除模型decorateQuery($query)
- 通过实体管理器的设置装饰查询