“Call to undefined method K2ModelItemlist::getCategoryChilds()” Error After Upgrading K2

After upgrading K2 of a Joomla website for a major international news agency to the latest version, we encountered the following error when testing the website:

Fatal error: Call to undefined method K2ModelItemlist::getCategoryChilds() in /modules/mod_jxtc_k2contentwall/mod_jxtc_k2contentwall.php on line 133

Obviously, the error states that a function that is currently used (called getCategoryChilds) no longer exists in the new K2. We did some investigation and we discovered that the function is now named getCategoryChildren. So, all that we needed to do was to replace line 133 in the file mod_jxtc_k2contentwall.php that exists under the /modules/mod_jxtc_k2contentwall/ directory with this line:

$aux = K2ModelItemlist::getCategoryChildren($id, true);

Replacing line 133 with the above code fixed the problem, but we have to say that we were disappointed with K2 since it is an extension which is known to be backward compatible with its previous versions. We know that the developers wanted to be grammatically correct (plural of child is children, and not childs) and had the best intentions when they changed the name of the function, but by doing so they broke some legacy code.

A smart way of addressing the problem would have been creating another method in the K2ModelItemlist class that calls the new function in order to maintain support for previous code. Here’s the method:

function getCategoryChilds($id, true){
	return K2ModelItemlist::getCategoryChildren($id, true);

Implementing the above function will ensure that websites using the legacy getCategoryChilds function will not be broken when they upgrade K2.

Again, we think that K2 is one of the better extensions out there (especially when it comes to backward compatibility), and that’s why we were disappointed with that oversight.

By the way, we would like to take the opportunity to state that K2 upgrades are much more smoother than Joomla’s migration (which are very painful and take a lot of time). K2 items are migrated properly, comment association with articles is maintained, and the look and feel does not change because it is controlled by K2’s template.

If you’re upgrading/migrating your Joomla website, or just your K2 component, and you’re facing problems, then we urge you to contact us! Our prices are affordable, our work is professional, we are very friendly, and we are very, very fast!

One Response to ““Call to undefined method K2ModelItemlist::getCategoryChilds()” Error After Upgrading K2”
  1. Comment by David — March 4, 2013 @ 12:10 pm

    I really appreciate your sharing this. Your suggestions put me on the right track after getting strange errors following a K2 upgrade.

Leave a comment