I have a module, that does some stuff and needs the data from the list model of my component. Everything is coded in MVC pattern using the Joomla framework.

When clicking on a menu item the list model is outputting data to the view and displaying it. Just like an list of article items.

Now i need that data in the module, but when writing something like this:

$objects = BaseDatabaseModel::getInstance('Objects', 'MyModel', array('ignore_request' => true));
$data = $objects->getItems();

There is a new model instance created. Now my model does a lot performance heavy stuff and i need exactly the data that is allready created once and used in the listing output. Why create another instance and trigger the same query twice? I my case always creating a model object is not wanted.

There is a nice article about the subject here, but no solution for getting a singleton instance is provided: https://magazine.joomla.org/all-issues/july-2014/why-the-poor-old-singleton-was-banned

Is there a singleton way to get the data of internal memory based cache Joomla Model is creating in another place like a module?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.