奇怪的是,標準的方式沒有工作,但我管理它的工作方式不同。我只需要添加自定義字段:
<?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"
/>
而現在它工作得很好。 那麼有很多東西需要改進,例如,添加類似樹木的填充等等。
'categoryedit'顯示類別ID號,所以它看起來好,但'category'仍然只顯示根條目:( –