简体   繁体   English

Joomla自定义组件-加载表单文件时出错

[英]Joomla Custom Component - Error loading form file

Currently, I've been trying to get familiar with programming custom components for Joomla 3.4.8. 目前,我一直在尝试熟悉Joomla 3.4.8的自定义组件的编程。 Therefore I've installed a new joomla website on my Raspberry Pi 2 for test purposes. 因此,出于测试目的,我在Raspberry Pi 2上安装了一个新的joomla网站。 Everything is working as it schould. 一切都按预期进行。

Then I started to do the ' Developing an MVC Component ' Tutorial provided by Joomla itself. 然后,我开始做由Joomla本身提供的“ 开发MVC组件 ”教程。 Everything worked fine until the point 7 ' Using the database '. 一切正常,直到第7点“ 使用数据库 ”为止。

Although this point talks about the database, the problem is to get the field types to work. 尽管这是关于数据库的,但问题是要使字段类型起作用。 Ie when I want to add a new menu item (in the administrator part), and I select the custom menu item type, I get an error which states "Error loading form file". 即,当我想添加新菜单项(在管理员部分),并且选择自定义菜单项类型时,出现错误,提示“加载表单文件时出错”。

I've been trying to find the error for several days, without success. 我已经尝试了几天的错误,但没有成功。 I even went so far to track the code line inside the joomla framework which throws this error. 我什至走得很远,在joomla框架内跟踪代码行,这引发了此错误。 The code line is inside /libraries/legacy/model/form.php (line 192). 代码行位于/libraries/legacy/model/form.php (第192行)。 At this line you can see $this->preprocessForm($form, $data); 在这一行中,您可以看到$this->preprocessForm($form, $data); . But somehow the code does not even enter this method, it simply throws an exception. 但是某种程度上,代码甚至没有输入此方法,它只是引发了一个异常。

I compared the $form and $data variable with the ones from a normal run by adding the following statement (found here ) before the line 192: 通过在第192行之前添加以下语句(在此处找到),我将$form$data变量与正常运行的变量进行了比较:

 echo "<pre>"; print_r($arr); echo "</pre>"; 

The $form variables does not have any difference. $form变量没有任何区别。 The $data variables however are slightly different. 但是$data变量略有不同。 Unfortunately I'm pretty new to these concepts, so I don't really know what could be wrong or where to search for the problem. 不幸的是,我对这些概念还很陌生,所以我真的不知道可能出什么问题或在哪里寻找问题。

Hopefully, somebody of you can help me out... 希望你们中的某人能帮助我...

For completion here is the output of the $data variable when the error is triggered: 为了完成,以下是触发错误时$data变量的输出:

    Array
(
    [parent_id] => 1
    [level] => 
    [lft] => 
    [rgt] => 
    [alias] => 
    [id] => 
    [menutype] => mainmenu
    [title] => 
    [note] => 
    [path] => 
    [link] => index.php?option=com_helloworld&view=helloworld
    [type] => component
    [published] => 
    [component_id] => 10000
    [checked_out] => 
    [checked_out_time] => 
    [browserNav] => 0
    [access] => 
    [img] => 
    [template_style_id] => 0
    [params] => Array
        (
            [menu-anchor_title] => 
            [menu-anchor_css] => 
            [menu_image] => 
            [menu_text] => 1
            [page_title] => 
            [show_page_heading] => 
            [page_heading] => 
            [pageclass_sfx] => 
            [menu-meta_description] => 
            [menu-meta_keywords] => 
            [robots] => 
            [secure] => 0
        )
    [home] => 0
    [language] => 
    [client_id] => 
    [request] => Array
        (
            [option] => com_helloworld
            [view] => helloworld
        )
    [menuordering] => 0
    [toggle_modules] => 1
)

Okay! 好的! I finally solved the issue. 我终于解决了这个问题。 Unfortunately it was a very stupid mistake... 不幸的是,这是一个非常愚蠢的错误。

First of all I noticed that method preprocessForm($form, $data) had been overwritten by the subclass. 首先,我注意到preprocessForm($form, $data)已被子类覆盖。 Hence my echo statements wouldn't be executed. 因此,我的echo语句将不会执行。 This brought me down to the point where my xml file at <joomla-root>/components/com_helloworld/views/helloworld/tmpl/default.xml was loaded. 这使我进入了<joomla-root>/components/com_helloworld/views/helloworld/tmpl/default.xml xml文件加载点。

Unfortunately it didn't work. 不幸的是,它没有用。 And this was due to a minor mistake in the xml file. 这是由于xml文件中的一个小错误。 The mistake was very simple and stupid: 错误非常简单和愚蠢:

<fieldset name="request">
        <field
            name="id"
            type="helloworld"
            label="COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_LABEL"
            description="COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_DESC" 
            />
        </field>
</fieldset>

I simply closed the field tag twice, where the second closing tag was used in a previous step of the tutorial. 我只是简单地两次关闭了field标签,在本教程的上一步中使用了第二个结束标签。

Very stupid mistake which cost me several hours. 非常愚蠢的错误使我花费了几个小时。 At least I had some insights to the joomla code. 至少我对joomla代码有一些见识。 Hopefully this post avoids others searching countless hours for such a minor mistake. 希望这篇文章可以避免其他人在无数小时内搜索出如此小的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM