Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
向Joomla 3中的组件添加类别_Joomla_Components_Field_Categories_Builder - Fatal编程技术网

向Joomla 3中的组件添加类别

向Joomla 3中的组件添加类别,joomla,components,field,categories,builder,Joomla,Components,Field,Categories,Builder,我使用快速创建一些小组件。现在我正在创建简单的目录组件,是时候添加类别了,因为所有其他的想法似乎都很好,但有一个问题 所有类别的代码都创建得很好,我可以添加新的类别,它保存在DB中,但在我编辑目录项时,并没有看到任何此类cats。 我试图找出问题所在,并通过在列表模式下向某些项目和类别显示添加catid来简单地更改数据库,但在编辑模式下,combobox仍然只有根元素 我检查\models\forms\item.xml文件并找到字段描述: <!-- Catid Field. Type: C

我使用快速创建一些小组件。现在我正在创建简单的目录组件,是时候添加类别了,因为所有其他的想法似乎都很好,但有一个问题

所有类别的代码都创建得很好,我可以添加新的类别,它保存在DB中,但在我编辑目录项时,并没有看到任何此类cats。 我试图找出问题所在,并通过在列表模式下向某些项目和类别显示添加catid来简单地更改数据库,但在编辑模式下,combobox仍然只有根元素

我检查\models\forms\item.xml文件并找到字段描述:

<!-- Catid Field. Type: Category. (joomla) -->
<field
    type="category"
    name="catid"
    label="COM_SKYCATALOG_ITEM_CATID_LABEL"
    extension="com_skycatalog.list"
    required="true"
    show_root="true"
    description="COM_SKYCATALOG_ITEM_CATID_DESCRIPTION"
    published="true"
/>


看起来一切正常。

您确定
com\u skycatalog.list
正确吗?检查
#uu类别
表以确保使用了正确的上下文

你试过categoryedit吗

<field name="catid"
    type="categoryedit"
    extension="__EXTENSION__"
    label="JCATEGORY"
    required="true"
    default=""
/>

奇怪的是,标准方法不起作用,但我以不同的方式管理它。我只需添加自定义字段:

<?php

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

JFormHelper::loadFieldClass('list');

/**
 * skycatalog Form Field class for the skycatalog component
 *
 * @since  0.0.1
 */
class JFormFieldSkyCatalog extends JFormFieldList
{
    /**
     * The field type.
     *
     * @var         string
     */
    protected $type = 'skycatalog';

    /**
     * Method to get a list of options for a list input.
     *
     * @return  array  An array of JHtml options.
     */
    protected function getOptions()
    {
        $db    = JFactory::getDBO();
        $query = $db->getQuery(true);
        $query->select('id, title');
        $query->from('#__categories');
        // Retrieve only published items
        $query->where('#__categories.published = 1','and');
        $query->where("#__categories.extension like 'com_skycatalog.list'",'and');


        $db->setQuery((string) $query);
        $messages = $db->loadObjectList();
        $options  = array();

        if ($messages)
        {
            foreach ($messages as $message)
            {   
                    $options[] = JHtml::_('select.option', $message->id, $message->title);
            }
        }

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

        return $options;
    }
}

categoryedit
显示类别id号,这样看起来没问题,但是
类别
仍然只显示根条目:(
<field
    type="Skycatalog"
    name="catid"
    class="inputbox"
    label="COM_SKYCATALOG_ITEM_CATID_LABEL"
    extension="com_skycatalog"
    required="true"
    description="COM_SKYCATALOG_ITEM_CATID_DESCRIPTION"
    published="true"
/>