2
votes

I'm using Joomla 3.1 and I'm using template hacks to override mod_banners -

/mytemplate/html/mod_banners/default.php

Which is working fine.

However, the banners module calls the file:

/components/com_banners/models/banners.php

Which I can't seem to override. I've tried moving the file (and folders) into my /mytemplate/html folder, but that doesn't work.

I've also tried putting the following code into my banners default.php file:

JModelLegacy::addIncludePath(JPATH_ROOT.'/templates/home/com_banners/models/', 'BannersModel');
$model      = JModelLegacy::getInstance('Banners', 'BannersModel', array('ignore_request' => true));
$banners    = $model->getItems();

But that doesn't work either. Is there any way I can override the query in /com_banners/models/banners.php without changing the core files?

All I'm trying to do is to pull in the descriptions for each banner, without changing the core.

Thanks in advance!

1
You could write a database query in your override default.php. its not the best method, however writing a plugin is effort and changing core files is not the way forward - Lodder

1 Answers

1
votes

The only way to override a model in Joomla is to make your own version of the original, and load (register) it through a system plugin, before the model is accessed for the first time. For your use case, that is way too complicated.

Even if it is not good practice, since it breaks up the MVC structure, I'd fetch the data from within the template.

$db    = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('id, name, description')
      ->from('#__banners');
$db->setQuery($query);
$banners = $db->loadObjectList();

Now you can access all banner descriptions, fx. in a loop:

foreach ($banners as $banner) {
    echo $banner->id, ': ', $banner->description;
}