Jump to content

A way to get Category objects (not array) without SQL?


Recommended Posts

Hi, I was wandering, is there a way to have a list of category objects instead of arrays (like Category::getCategories() does)? I know I can do an sql query, but it sounds strange to me that there's no method to have an object list instead of an array list. Probably I'm missing something.


Also, when I get the category list, I got also Home and Root, that often are quite useless. A way to have a list without them (so that I fon't have to 'clean' the resulting default array).


Thank you!

Link to comment
Share on other sites

Too tech?

Anyway, found a partial answer by myself. Basically, I needed it to build a custom menu, and I needed a tree of category objects.

I've found that the Category class has a method named recurseLiteCategTree() that help a lot. It returns an array that contains a tree of arrays with id, link, name, description and children of each found category, accordingly with the passed parameters.


So, for example, say I want all the category tree starting from the Home Page (that ususually has id == 2);


$root = new Category(2);
$tree = $root->recurseLiteCategTree();


The method firm is like this:


recurseLiteCategTree($max_depth = 3, $current_depth = 0, $id_lang = null, $excluded_ids_array = null)


So as you can see, it's still possible go ahead and further refine the tree.


Still it's not a tree filled with real Category instances, but it's anyway really usefull. And one can always tweak it by overriding the Category class. It's quite simple. Hope it helps.

Edited by stratboy (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...