lsantos2015 Posted November 24, 2014 Share Posted November 24, 2014 Hello.. I'm with a little problem, when trying to get the full category parent array. I'm editing CategoryController.php, and need to get $var = CategoryCore::getParentsCategories($this->context->language->id); working, and I keep getting this Strict Standards: Non-static method CategoryCore::getParentsCategories() should not be called statically, assuming $this from incompatible context in /xxx/xxx/public_html/xxx/controllers/front/CategoryController.php on line 9999999 I'm how can I make this work, to retrieve an array with all categories id's.. Thanks in advance Link to comment Share on other sites More sharing options...
vekia Posted November 24, 2014 Share Posted November 24, 2014 this function is not static: classes/Category.tpl /** * Get Each parent category of this category until the root category * * @param integer $id_lang Language ID * @return array Corresponding categories */ public function getParentsCategories($id_lang = null) { $context = Context::getContext()->cloneContext(); $context->shop = clone($context->shop); if (is_null($id_lang)) it means that you can't call it with something::function you can call it only with $category = new Category(); $category->getParentsCategories(); ---------------- or just change it to static function public static function getParentsCategories($id_lang = null) { $context = Context::getContext()->cloneContext(); $context->shop = clone($context->shop); then you will be able to call it with Category::getParentCategories Link to comment Share on other sites More sharing options...
lsantos2015 Posted November 24, 2014 Author Share Posted November 24, 2014 HI.. Thanks for the prompt answer. If I change to static, I get this : Fatal error: Using $this when not in object context in /home3/lbss2015/public_html/rmc/classes/Category.php on line 1061 and using $category = new Category(); $category->getParentsCategories(); and using this, where do I put the actual category, because all I can get is a lot of empty fields, and the value 1, after 4 or 5 fields from the array.. This also does not work. $category = new Category($this->category->id); $category->getParentsCategories(); I'm a bit lost here.. Link to comment Share on other sites More sharing options...
FullCircles Posted November 24, 2014 Share Posted November 24, 2014 If you're adding something to the category controller itself, it should already have access to the category variable stored within itself, so could just try using: $this->category->getParentsCategories(); If you don't have any luck with that, could also try: $this->context->category->getParentsCategories(); That said, this bit you mentioned should have worked.. just to check, is it throwing an error, or are you just not storing the output of the function? $category = new Category($this->category->id); $category->getParentsCategories(); i.e. $var = $category->getParentsCategories(); Link to comment Share on other sites More sharing options...
lsantos2015 Posted November 24, 2014 Author Share Posted November 24, 2014 Hello FullCircles I tried what you mentioned, but no luck either, I can do it by hand, with a few foreach, while and so.. But if there is a function to do this, why is this not working out ?.. by the way, thanks for prompt reply.. Any thoughts on this.. ? Link to comment Share on other sites More sharing options...
FullCircles Posted November 24, 2014 Share Posted November 24, 2014 Does it actually throw any errors this time, or is it just not returning anything useful? Can't see any reason why any of these shouldn't be working really, it's odd Link to comment Share on other sites More sharing options...
gonebdg - webindoshop.com Posted November 26, 2014 Share Posted November 26, 2014 If object category has been initialized somewhere within your code, you don't have to initializing it again. So, code below is inappropriate : $category = new Category($this->category->id); $array_parent = $category->getParentsCategories(); To get each parent category from the existing object category, you just have to do like this : // Get array parent from the existing object Category $array_parent = $this->category->getParentsCategories(); But if the object category doesn't yet initialized, then you should do something like this : // Define id_category $id_category = (int)Tools::getValue('id_category'); // Initialize object Category $category = new Category((int)$id_category); // Get array parent from the initialized object Category $array_parent = $category->getParentsCategories(); 1 Link to comment Share on other sites More sharing options...
lsantos2015 Posted December 1, 2014 Author Share Posted December 1, 2014 Hello all.. With your help, my problem is solved.. Sorry for some delay, but I was away for a few days.. Thanks for all you help Luis Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now