【问题标题】:Adding category to component in Joomla 3在 Joomla 3 中向组件添加类别
【发布时间】:2017-12-20 21:10:44
【问题描述】:

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

类别的所有代码都创建得很好,我可以添加新类别并将其保存在数据库中,但是当我编辑目录项时没有看到任何这些猫。 我试图找出问题出在哪里,并通过在列表模式下将 catid 添加到某些项目和类别显示来简单地对数据库进行更改,但在编辑模式下,组合框仍然只有根元素。

我检查 \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"
/>

似乎一切正常。

【问题讨论】:

    标签: joomla components field categories builder


    【解决方案1】:

    你确定com_skycatalog.list 是正确的吗?检查#__categories 表以确保您使用的是正确的上下文。

    您尝试过 categoryedit 吗?

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

    【讨论】:

    • categoryedit 显示类别 ID 号,所以看起来没问题,但 category 仍然只显示根条目:(
    【解决方案2】:

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

    <?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;
        }
    }
    

    并更改字段类型:

    <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"
    />
    

    现在它工作得很好。 嗯,还有很多需要改进的地方,例如,向类别添加像填充这样的树等。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-02
      • 1970-01-01
      • 2014-05-18
      • 2017-09-02
      • 1970-01-01
      • 2011-08-25
      • 2016-01-31
      相关资源
      最近更新 更多