gpt4 book ai didi

php - Joomla 3.3 - 通过插件向所有菜单项添加自定义字段 - 参数未保存

转载 作者:可可西里 更新时间:2023-11-01 13:24:16 24 4
gpt4 key购买 nike

我在向 com_menus - 项目 View 添加自定义字段时遇到问题。

教程:(参见:http://docs.joomla.org/Adding_custom_fields_to_core_components_using_a_plugin)

教程效果很好(com_contact),但是当我想覆盖菜单项 View 时:参数未保存!!!

下面是我用来确定添加自定义表单的组件和 View 的代码。

class plgContentPluginName extends JPlugin {

function onContentPrepareForm($form, $data) {

$app = JFactory::getApplication();
$option = $app->input->get('option');
$view = $app->input->get('view');

switch($option) {

case 'com_menus': {
if ($app->isAdmin() && $view == 'item') {
JForm::addFormPath(__DIR__ . '/forms');
$form->loadFile('item', false);
}
return true;
}

}
return true;

}
}

这是正在加载的 item.xml (/forms/item.xml)

<?xml version="1.0" encoding="UTF-8"?>    
<form>
<fields name="params">
<fieldset name="params" label="Custom Fields">
<field name="param1" type="text" label="lbltext"/>
<field name="param2" type="text" label="lblText2"/>
</fieldset>
</fields>
</form>

当我创建或编辑菜单项时,表单可以正确呈现,但当我点击“保存”时,值不会被保存。

谢谢。

最佳答案

我通过删除 If block 中的 $view == 'item' 条件解决了这个问题。

最后看起来像这样:

class plgContentPluginName extends JPlugin {

function onContentPrepareForm($form, $data) {

$app = JFactory::getApplication();
$option = $app->input->get('option');

switch($option) {

case 'com_menus': {
if ($app->isAdmin()) {
JForm::addFormPath(__DIR__ . '/forms');
$form->loadFile('item', false);
}
return true;
}

}
return true;
}

item.xml 保持不变。

顺便说一句:我现在使用的是 Joomla 3.4.1 版。

关于php - Joomla 3.3 - 通过插件向所有菜单项添加自定义字段 - 参数未保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25832262/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com