A
A
Alexey Nikolaev2014-10-06 04:24:53
CMS
Alexey Nikolaev, 2014-10-06 04:24:53

How to get category instance for your component in Joomla?

Good time. There was a strange problem: I'm trying to get a category instance for my component, according to the docs, I use the following code for this:

jimport( 'joomla.application.categories' );
$categories = JCategories::getInstance('Mycomponent');

However, the result is false. If you get categories from a standard component, for example, Content, the correct object will be returned. The component incorporates support for the system's native categories (via com_categories).
Why can there be such a result when there are categories, but instance cannot be obtained?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Nikolaev, 2014-10-06
@Heian

In the component, in order to be able to get an instance, you need to create a helper class that inherits the required parent. For categories it will be /helpers/category.php with content

class MycomponentCategories extends JCategories {
  public function __construct($options = array())	{
    $options['table'] = '#__mytable';
    $options['extension'] = 'com_mycomponent';

    parent::__construct($options);
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question