I'm trying to get an instance of a com_menus model from within my component. The following code works:

JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_menus/models/');
$model = self::getInstance('Item', 'MenusModel');

and gives me an instance of the menu item model which I can manipulate as I need, but this code

self::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_menus/models/');
$model = self::getInstance('Item', 'MenusModel');

doesn't not give me a model, it just gives me false.

My component model extends JModelList. In my model, if I call self::addIncludePath, I get a different result than when I call JModelLegacy::addIncludePath, even thought the static function addIncludePath is the same (JModelList is an alias for ListModel, which extends BaseDatabaseModel that defines the static function addIncludePath and JModelLegacy is an alias of BaseDatabaseModel).

The same static method is being executed, but clearly the context is making a difference in the result, but I don't understand why.

Why does calling the same static method in two different ways give two different results?

What is the correct/preferred way of instantiating a core component's model from with a component I'm developing? It seems odd to still be using JModelLegacy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.