No Code Attached Yet Information Required
avatar OctavianC
OctavianC
13 Jul 2022

Steps to reproduce the issue

$categories = new JCategories(array('extension' => 'com_content', 'table' => '#__content'));
print_r($categories->get('root'));

Expected result

Joomla\CMS\Categories\CategoryNode Object
(
    [id] => root
    [asset_id] => 0
    [parent_id] => 0
...

Actual result

Resource 'Joomla\CMS\Categories\DatabaseInterface' has not been registered with the container.

System information (as much as possible)

Latest nightly
These packages were last built: Wednesday, 13 July 2022 00:11:27 UTC

Additional comments

Can be fixed by calling $categories->setDatabase(JFactory::getDbo()); but that seems a B/C break. Code works on Joomla! 4.1.5 fine.

avatar OctavianC OctavianC - open - 13 Jul 2022
avatar joomla-cms-bot joomla-cms-bot - change - 13 Jul 2022
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 13 Jul 2022
avatar chmst
chmst - comment - 13 Jul 2022

Where did you find this line? Which Version of Joomla, which Version of which extension?

$categories = new JCategories(array('extension' => 'com_content', 'table' => '#__content'));``

avatar chmst chmst - change - 13 Jul 2022
Labels Added: Information Required
avatar chmst chmst - labeled - 13 Jul 2022
avatar OctavianC
OctavianC - comment - 13 Jul 2022

It's just an example. Obivously it's an extension that uses the Categories class but that's not the point.

Here, use this code which is according to the docs:

use Joomla\CMS\Categories\Categories;

class TestCategories extends Categories
{
    public function __construct($options = array())
    {
        $options['table']      = '#__test_items';
        $options['extension']  = 'com_test';
        $options['statefield'] = 'published';

        parent::__construct($options);
    }
}

$categories = JCategories::getInstance('Test');
var_dump($categories->get('root'));

4.2.0 Result

0 Resource 'Joomla\CMS\Categories\DatabaseInterface' has not been registered with the container.

4.1.5 Result

object(Joomla\CMS\Categories\CategoryNode)[894]

avatar OctavianC
OctavianC - comment - 13 Jul 2022

Found it

avatar brianteeman
brianteeman - comment - 13 Jul 2022

and?

avatar OctavianC OctavianC - change - 13 Jul 2022
Status New Closed
Closed_Date 0000-00-00 00:00:00 2022-07-13 17:11:40
Closed_By OctavianC
avatar OctavianC OctavianC - close - 13 Jul 2022
avatar OctavianC
OctavianC - comment - 13 Jul 2022

... and I've fixed it. Please test #38269

Add a Comment

Login with GitHub to post a comment