emlynwest / setui
FuelPHP嵌套集UI模块
This package is auto-updated.
Last update: 2024-09-04 23:33:00 UTC
README
模块,用于为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
目录中的文件符号链接到适当的资源文件夹。虽然您可以复制这些文件,但这样做意味着您必须手动更新资源,当模块更新时。
一旦JavaScript被包含在页面中,它将自动折叠非活动分支,并允许分支被打开和关闭。
需要jQuery 1.7或更高版本。
测试
由于在应用程序外部测试FuelPHP v1模块的复杂性,目前该模块没有单元测试。
致谢
三角形图标由Elegant Themes提供,来自www.flaticon.com,受CC BY 3.0许可。