stevewest/setui

该软件包已被废弃且不再维护。作者建议使用emlynwest/setui软件包。

FuelPHP嵌套集合的UI模块

安装: 10

依赖项: 0

建议者: 0

安全: 0

星级: 3

关注者: 3

分支: 0

类型:fuel-module

0.1.0 2015-09-11 14:44 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:51:12 UTC


README

Latest Version

提供FuelPHP嵌套集合模型基本用户界面的模块。

安装说明

只需运行 composer require emlynwest/setui

或者

将以下内容添加到您的 composer.json

{
    "require": {
        "stevewest/setui": "dev-master"
    },
}

然后只需运行 composer update

之后,您只需在FuelPHP应用程序的配置文件中启用该模块。

自定义模块位置

如果您的应用程序使用非标准模块位置,则可以将以下内容添加到您的 composer.json 中,以确保模块安装到正确的位置。(确保保留 {$name}。)

{
    "extra": {
        "installer-paths": {
            "my/custom/path/{$name}": ["stevewest/setui"]
        }
    }
}

用法

菜单渲染

使用 SetUI\Menu 类可以将嵌套集合模型渲染成列表。构造函数接受一个可选的配置数组,可用于控制集合渲染的行为。以下是每个项目的默认配置以及它们可以用来做什么的说明。

<?php
$config = [
    // This is each leaf of the tree, by default it has a link and a list of children
    'leafView' => 'setui::setui/leaf',
    
    // This is the list of children for each leaf
    'listView' => 'setui::setui/list',
    
    // This is the top level container, it can be used for adding style around the list
    'containerView' => 'setui::setui/container',
    
    // If not set to null will be treated as an instance of Theme for loading views
    'themeInstance' => null,
    
    // Property name of the model to load the leaf name from
    'nameProperty' => 'name',
    
    // Set to true to display the root node of the tree
    'includeRoot' => false,
    
    // What to prepend to the URL before it is passed to Uri::create()
    'uriPrefix' => '',
    
    // URI string that denotes the currently active node path (eg "parent/child/grandchild")
    'activePath' => '',
];

要渲染集合,只需创建一个 SetUI\Menu 的新实例,然后调用 build() 方法。

<?php
$menu = new \SetUI\Menu($config);

$set = Model_Tree::forge()->set_tree_id(1)->root()->get_one();

// $tree contains the top level View object
$tree = $menu->build($set);

关于路径生成的说明

路径名称使用嵌套集合的 path() 方法生成,要确保您得到正确的路径,请确保您的嵌套集合树配置中 title_field 设置为正确的列名。虽然SetUI不关心这是什么,但通常最好使用URL友好的属性,例如使用slug观察器生成的属性。

JavaScript

该模块还包括一些基本的JavaScript,允许更好的用户交互。要启用此功能,您需要将 assets 中的文件符号链接到相应的资产文件夹。虽然您可以复制文件,但这意味着您必须手动更新资产,当模块更新时。

一旦JS被包含在页面中,它将自动折叠非活动分支,并允许打开和关闭分支。

需要jQuery 1.7或更高版本。

测试

由于在应用程序之外测试FuelPHP v1模块的复杂性,目前该模块没有进行单元测试。

致谢

三角形图标由Elegant Themes提供,来源www.flaticon.com,授权方式CC BY 3.0