Create test site with 3 categories. Call JCategories::getInstance('Content')->get('root')->getChildren(true);
Array of 3 categories.
Array of single category item.
OpenServer, PHP 5.4, Joomla 3.3.6.
Actually, an array is returned containing a single element of type JCategoryNode for the Uncategorized category.
In this object you will find (amongst a lot of stuff...) a [_parent:protected] element pointing to the root node with all its children (the [_nodes:protected] array).
I'm unsure if this is the expected behavior... (probably not...)
I used this code to "dump" the object:
defined('_JEXEC') or die;
define('BR', '<br/>');
class SMZ_Tester {
public static function executeTest() {
$r = '';
$r .= 'Date time is: ';
$r .= strftime("%Y-%m-%d %H:%M:%S") . BR;
$cats = JCategories::getInstance('Content')->get('root')->getChildren(true);
$r .= BR . 'Categories:' . BR;
$r .= print_r($cats, true);
return $r;
}
}
Thank you for the reply. I've also used var_dump and saw, that all categories can be accessed via private members, but it's definitely not an expected behaviour.
In my case, the single element returned was user-defined category, not uncategorized.
Ah... I thought the category with the lowest ID (normally Uncategorized) would always be returned, but this evidently is a "false assumption". I will look at the code...
I'm wondering what will happen if a "deeper" (2nd or 3rd level) category is returned: the _parent at that point would not be root...
hmmm... we are probably making some mistake or false assumption...
This is what the model for "List All Categories" does (guaranteed functioning!)
$categories = JCategories::getInstance('Content', $options);
$this->_parent = $categories->get($this->getState('filter.parentId', 'root'));
if (is_object($this->_parent))
{
$this->_items = $this->_parent->getChildren($recursive);
}
else
{
$this->_items = false;
}
| Priority | Urgent | ⇒ | Medium |
The code is roughly equivalent to the following:
$cat = JCategories::getInstance('Content', $options)->get('root');
$items = is_object($cat) ? $cat->getChildren($recursive) : false;
Probably options differ from the default, but it still gives no light on a problem.
I agree, but I tried your same code and... no way!
| Status | New | ⇒ | Confirmed |
| Labels |
Added:
?
|
||
| Status | Confirmed | ⇒ | Closed |
| Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2015-05-08 22:28:38 |
| Closed_By | ⇒ | zero-24 |
Confirmed with Joomla 3.4.0-dev
I'm looking into this...