fede91it / fof-nnrelation
支持FOF(框架在框架上)的许多对多关系。
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-09-24 03:44:04 UTC
README
FOF NNRelation为FOF(框架在框架上)添加了许多对多关系的支持。实际上,它是为FOF准备的!它包含一组F0FTableBehavior、一个F0FModelBehavior和一个F0FFormField。添加所有这些神奇的类,就可以轻松地在你的FOF项目中使用多关系(带有枢纽表)!
需求
- Joomla 3.x(也应适用于2.5.x)
- FOF 2.3.x或更高版本(下载 Framework on Framework)
准备
- 安装
lib_f0f-nnrelation-1.0.0.tgz
库扩展 - 为你的FOF组件创建一个
dispatcher.php
文件 - 覆盖
onBeforeDispatch
方法 - 在调用
parent::onBeforeDispatch
之前,以此方式包含f0f-nnrelation
class FoobarDispatcher extends F0FDispatcher { public function onBeforeDispatch() { // Add multiple to multiple relations support jimport('f0f-nnrelation.fields.nnrelation'); jimport('f0f-nnrelation.fields.header.nnrelation'); jimport('f0f-nnrelation.models.nnrelation'); jimport('f0f-nnrelation.tables.nnrelation'); return parent::onBeforeDispatch(); } }
使用方法
表行为
在你的 form.form.xml
文件中,你可以使用一种新的字段类型,称为 nnrelation
。
<field name="players" type="nnrelation" multiple="true" label="COM_FOOBAR_FIELD_PLAYERS_LABEL" tooltip="COM_FOOBAR_FIELD_PLAYERS_DESCRIPTION"/>
名称属性 必须 与你在 fof.xml
文件中声明的多关系名称相同。在上面的例子中,我要管理多关系的声明方式如下
<table name="team"> <relation name="players" type="multiple" pivotTable="#__foobar_players_teams"/> <behaviors>nnrelation</behaviors> </table>
如你所见,你 必须 启用特定FOF行为,以使用多关系的表。在这个例子中,多关系将自动管理所有想要跟踪其 players
的 team
项目。如果你想反过来,你必须为 player
表声明相反的 teams
关系,并在那里启用行为。名称遵循FOF的常规单复数约定。
模型行为
在你的组件前端,你可以轻松检索多关系。为此,你可以启用视图的 nnrelation
行为,如果这里声明了多关系,所有相关项目都将自动检索。
<view name="teams"> <config> <option name="behaviors">nnrelation</option> </config> </view>
现在在你的列表视图中,$this->items
数据对象将包含一个以关系命名的属性。相反,你将在项目视图中使用 $this->item
。
stdClass Object
(
[title] => Foobar Team
[players] => stdClass Object
(
[0] => Array
(
[title] => John
[...] => ...
)
[2] => ...
)
)
表单字段
在你的 form.default.xml
文件中,你可以使用一种新的字段类型,称为 nnrelation
。
<field name="players" type="nnrelation" empty_replacement="COM_FOOBAR_NO_PLAYERS_LABEL" url="index.php?option=com_foobar&view=player&id=[ITEM:FOOBAR_PLAYER_ID]" show_link="true"/>
在这种情况下,字段的名称也应反映在 fof.xml
中声明多关系的名称。其他属性继承自 list
表单类型(请参阅FOF文档)。占位符 [ITEM:FOOBAR_PLAYER_ID]
是你引用表中枢纽表中的键值名称。
表单标题
即将推出...