如何获取自定义扩展或第三方组件的类别


8

我有一个第三方组件,将其类别存储在#__categories表中。

-----+----------------+-----------------------+-----------------------+-----
...  | extension      | title                 | alias                 | ...
-----+----------------+-----------------------+-----------------------+-----
...  | com_content    | Uncategorised         | uncategorised         | ...
-----+----------------+-----------------------+-----------------------+-----
...  | com_banners    | Sample Data-Banners   | sample-data-banners   | ...
-----+----------------+-----------------------+-----------------------+-----
...  | com_newsfeeds  | Sample Data-Newsfeeds | sample-data-newsfeeds | ...
-----+----------------+-----------------------+-----------------------+-----
...  | com_contact    | Sample Data-Contact   | sample-data-contact   | ...
-----+----------------+-----------------------+-----------------------+-----
...  | com_content    | Joomla!               | joomla                | ...
-----+----------------+-----------------------+-----------------------+-----
...  | com_thirdparty | ThirdParty Category   | thridparty-category   | ...
-----+----------------+-----------------------+-----------------------+-----
...  | ...            | ...                   | ...                   | ...
-----+----------------+-----------------------+-----------------------+-----

我可以从下面com_banners或从下面的其他核心组件中打印类别,

$categories = JCategories::getInstance('Banners');
$subCategories = $categories->get()->getChildren(true);
print_r($subCategories);

但这表明

致命错误:在第152行的... \ libraries \ legacy \ categories \ categories.php中找不到类'ThirdPartyCategories'”

尝试按以下方式打印另一个扩展的类别时,

$categories = JCategories::getInstance('ThirdParty');
$subCategories = $categories->get()->getChildren(true);
print_r($subCategories);

我与joomla库中的旧类别有什么关系?

注意:该名称ThirdParty仅是一个占位符,可以是任何第三方扩展名。


ThirdParty组件的实际名称吗?
罗德(Lodder),2015年

不,它只是一个占位符,可以是任何第三方扩展名。以我为例,它是com_thirdparty
kolunar 2015年

Answers:


6

经过研究后,事实证明,我正在使用的第三方组件没有创建文件,..\components\com_thirdparty\helpers\category.php 而该文件是实现在组件的helpers目录中ThirdPartyCategories扩展的类所必需的,JCategories如下所述

defined('_JEXEC') or die;

/**
 * ThirdParty Component Category Tree
 */
class ThirdPartyCategories extends JCategories
{
    /**
     * Constructor
     *
     * @param   array  $options  Array of options
     */
    public function __construct($options = array())
    {
        $options['table']      = '#__thirdparty';
        $options['extension']  = 'com_thirdparty';
        $options['statefield'] = 'published';
        parent::__construct($options);
    }
}

如果您已经适当回答了自己的问题,请将其设置为您选择的答案,以将其从未回答的问题列表中删除。
garth 2015年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.