dioscouri/f3-modules

F3框架的模块组件

v0.9.0 2015-09-01 21:42 UTC

This package is not auto-updated.

Last update: 2024-09-14 16:44:57 UTC


README

F3框架的模块管理器

入门指南

Add this to your project's composer.json file:

{
    "require": {
        "dioscouri/f3-modules": "dev-master"
    }
}

然后,将以下两行代码添加到您的 index.php 文件中,在 $app->run(); 之前立即添加:

// bootstap each mini-app
\Dsc\Apps::instance()->bootstrap();

// trigger the preflight event
\Dsc\System::instance()->preflight(); 

向系统中添加模块位置

您的前端模板可能包含几个自定义模块位置(页眉、页脚、左侧、右侧等)。使用以下代码通知 f3-admin,您应该在 apps/site/bootstrap.php 中添加此代码:

// register the template'e module positions
\Modules\Factory::registerPositions( array('promo', 'footer', 'above-content', 'below-content') );

在模板中显示模块位置

将以下代码添加到您的模板文件中,以在“页脚”位置渲染模块。

<tmpl type="modules" name="footer" />

在视图文件中显示模块位置

使用以下代码在您的某个视图中渲染模块位置。

echo \Modules\Factory::render( 'your_custom_position_name', \Base::instance()->get('PARAMS.0') );

将您项目的模块添加到系统中

要将您自己的自定义模块添加到系统中,请将它们全部放入您自己的 \Modules 文件夹的子文件夹中,例如

/apps/site/modules/

结果如下

/apps/site/modules/custom_module_1/
/apps/site/modules/custom_module_2/

然后,将您的模块文件夹注册到系统中

// register the modules path
\Modules\Factory::registerPath( $f3->get('PATH_ROOT') . "apps/site/modules/" );

模块文件系统结构

  1. 每个模块都必须在其文档根目录中有一个 module.json 文件,其内容是一个包含至少一个标题(唯一的)的单个 JSON 对象,例如
{
    "title": "Your Custom Module"
}
  1. 每个模块都必须在其文档根目录中有一个 Module.php 文件,其中包含一个类。该类应该是命名空间化的(例如 \Your\Custom\Namespace)且类名为 'Module'。最后,该类必须扩展 \Modules\Abstracts\Module

引导您的模块

您的所有模块都可以有自己的 bootstrap.php 文件,因此可以有自己的监听器。将 bootstrap.php 文件放在它们的文件夹根目录中,例如

/apps/site/modules/custom_module_1/bootstrap.php
/apps/site/modules/custom_module_2/bootstrap.php

向 f3-admin 模块编辑表单添加自定义字段

您的模块的监听器可以向 f3-admin 模块编辑表单添加自定义 HTML。请参阅核心 Megamenu 模块以获取一个工作示例

f3-modules/src/Modules/Modules/Megamenu/Listeners/Admin.php