2017-07-16 117 views
0

我使用Joomla Component Builder来快速创建一些小组件。现在我创建简单的目录组件和时间来添加类别,因为所有其他的想法似乎工作得很好,但有一个问题。将类别添加到Joomla 3中的组件

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

我检查\型号\表格\ 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" 
/> 

似乎一切ok。

回答

0

奇怪的是,标准的方式没有工作,但我管理它的工作方式不同。我只需要添加自定义字段:

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

而现在它工作得很好。 那么有很多东西需要改进,例如,添加类似树木的填充等等。

0

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

您是否尝试过使用categoryedit?

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

'categoryedit'显示类别ID号,所以它看起来好,但'category'仍然只显示根条目:( –