Joomla 2.5 Load custom field in components layout fatal error

孤街醉人 提交于 2019-12-11 05:09:10

问题


Im trying to load custom field in my backend component default view (default.php):

JFormHelper::addFieldPath(JPATH_COMPONENT . '/models/fields');
$productType = JFormHelper::loadFieldType('ProductType',false);

$productTypeOptions = $productType->getOptions(); 

But I get a fatal error:

Fatal error: Call to a member function children() on a non-object in xxx\libraries\joomla\form\fields\list.php on line 89

When I load this custom field into the form, everything works perfectly.

Any ideas?


回答1:


Make sure you are adding the correct path to the fields




回答2:


In your $productType->getOptions() function, Try removing:
$options = array_merge(parent::getOptions(), $options);




回答3:


Well, I tried to expand my fellow above idea but it seemed an inappropiate edit, I put it here then:

This worked for me. In your getOptions, if you have something like the getOptions found here (http://docs.joomla.org/How_to_add_custom_filters_to_component_admin), you´ll have this line:

$options = array_merge(parent::getOptions(), $options);

This is the one that makes the error. Why? Well, I´m not sure. If you see the related file, you´ll find this:

foreach ($this->element->children() as $option)

So the problem is that you are calling children() on the model parent that it seems is not initialized. Why the array_merge is needed? Is discussed here (http://forum.joomla.org/viewtopic.php?f=626&t=782877)

My explanation is more like a dirty blind patch, but hope it helps to move forward.



来源:https://stackoverflow.com/questions/13861563/joomla-2-5-load-custom-field-in-components-layout-fatal-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!