Skip to main content
Update with code from question for context
Source Link
Sharky
  • 12k
  • 8
  • 23

In CMS context you can get the component through the active application. The component may not necessarily support categories so it's a good idea to check if it implements the required interface:

$component = Joomla\CMS\Factory::getApplication()->bootComponent('content');

if (!$component instanceof Joomla\CMS\Categories\CategoryServiceInterface)
{
    // Component does not support categories. Bail here.
}

$categories = $component->getCategory();
$cat        = $categories->get($id);
return  $cat->getChildren();

In CMS context you can get the component through the active application. The component may not necessarily support categories so it's a good idea to check if it implements the required interface:

$component = Joomla\CMS\Factory::getApplication()->bootComponent('content');

if (!$component instanceof Joomla\CMS\Categories\CategoryServiceInterface)
{
    // Component does not support categories. Bail here.
}

$categories = $component->getCategory();

In CMS context you can get the component through the active application. The component may not necessarily support categories so it's a good idea to check if it implements the required interface:

$component = Joomla\CMS\Factory::getApplication()->bootComponent('content');

if (!$component instanceof Joomla\CMS\Categories\CategoryServiceInterface)
{
    // Component does not support categories. Bail here.
}

$categories = $component->getCategory();
$cat        = $categories->get($id);
return  $cat->getChildren();
Source Link
Sharky
  • 12k
  • 8
  • 23

In CMS context you can get the component through the active application. The component may not necessarily support categories so it's a good idea to check if it implements the required interface:

$component = Joomla\CMS\Factory::getApplication()->bootComponent('content');

if (!$component instanceof Joomla\CMS\Categories\CategoryServiceInterface)
{
    // Component does not support categories. Bail here.
}

$categories = $component->getCategory();