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!
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;
}
Related
I've been looking all over the web on how I would go about retrieving filtered products and then get their respective attributes using getAdditionalData. Here's what I do:
$_collectionProduct=Mage::getModel('catalog/product')
->getCollection()
->addAttributeToFilter('status', array('eq' =>1))
->addAttributeToFilter('attribute_set_id',9)
->addAttributeToSelect('*');
This works and retrieves all the filtered products. However, now I need their attributes so I am looping
foreach ($_collectionProduct as $products) {
$_additional = $product->getAdditionalData();
}
What happens is that $_additional returns NULL.
Another scenario I have tried is the following
foreach ($_collectionProduct as $_products) {
$product= Mage::getModel("catalog/product")->load($_product->getId());
$_additional = $product->getAdditionalData();
}
This example still displays NULL. Would really appreciate if somebody would have a solution to the dilemma. Thanks.
I actually figured out why it wasn't working. It appears that getAdditionalData() is not really attached to a specific product. The product view is calling this function from core file. The actual function I needed to use was getAttributes().
In my extension, I've retrieved articles from the content table like this:
.......
.......
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('id, catid, title, introtext, attribs);
$query->from('#__content');
$query->where('catid="'.$cid.'"');
$query->where('state="1"');
.......
.......
Here I can retrieve attribs data for each article being retrieved.
Is there an easy way to retrieve article params from the global settings (is there some sort of static function in Joomla?) or do I need to manually retrieve the params from the extensions table?
You might want to use the JComponentHelper class to get the params of the component.
<?php
jimport( 'joomla.application.component.helper' );
$com_content_params = JComponentHelper::getParams('com_content');
To get the articles I wouldn't write the query myself as you do, but use the relevant JModel (JModelLegacy in Joomla 3) instance instead.
Something that would look like:
<?php
$model = JModel::getInstance('Articles', 'ContentModel');
$model->setState('filter.category_id', (int)$cid);
$articles = $model->getList();
Don't know if that specific code will work, but you certainly can do some research on Google about that. The spirit is there: use the classes provided by Joomla instead of pulling stuff directly from the DB. You'll gain in maintainability and code quality.
Hi i kinda found the way to display the modules in the component but i am wondering how could i save the parameters through component i mean editing the values in component and saving it.
The modules names and paramaters are known in advance. So the calling will be like this
jimport( 'joomla.application.module.helper' );
$module = &JModuleHelper::getModule( "ModuleName");
$params = new JParameter($module->params);
The purpose of doing so is to ease editing certain values for the customer so it is a pain for a newbie to browse all that joomla stuff(in my case).
All in all cant figure out, how to save the params of a module(s)
Hi this is the code to save the params of a component, module or plugin in Joomla.
It first loads the current params, makes its changes, then saves again; ensure you always load the current params first.
$mparams = JComponentHelper::getParams( 'com_littlehelper' );
$params = $mparams->get('params');
$mparams->set('params.favicons_sourcepath','icons');
$this->saveParams($mparams, $this->componentName);
private function saveParams($params, $extensionName, $type='component') {
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->update('#__extensions AS a');
$query->set('a.params = ' . $db->quote((string)$params));
$query->where(sprintf('a.element = %s AND a.%s = %s',
$db->quote($extensionName),
$db->quoteName('type'),
$db->quote($type)
));
$db->setQuery($query);
return $db->execute();
}
This code comes from my extension LittleHelper published on the JED.
is there a possibility to trigger an update of the cache if a DataObject is edited?
for example updating a News DataObject should update the cache of pages, that are displaying these NewsObjects.
many thanx,
Florian
Here is what I could do using the StaticPublishQueue module. In your NewsDataObject.php:
function onAfterWrite() {
parent::onAfterWrite();
$url = array();
$pages = $this->Pages(); //has_many link to pages that include this DataObject
foreach($pages as $page) {
$pagesAffected = $page->pagesAffected();
if ($pagesAffected && count($pagesAffected) > 0) {
$urls = array_merge((array)$urls, (array)$pagesAffected);
}
}
URLArrayObject::add_urls($urls);
}
This takes each of the pages that references your DataObject, asks it for all it's URL and the URL of any related pages (e.g. Virtual Pages that reference that page), compiles all the URLs into a big array, then adds that array to the static publishing queue. The queue will gradually process until all the affected pages are republished.
The event system allows you to add a layer of abstraction between the republishing and the triggers for republishing, but for something simple you don't necessarily need to use it. Instead, you can add pages to the queue directly. (You might also like to read this blog post describing the StaticPublishQueue module)
The StaticPublisherQueue module will handle that for you.
In case anyone else comes across this, and doesn't wish to use the StaticPublishQueue module instead of StaticPublisher, it does appear to be possible in StaticPublisher, the following works for me:
function onAfterWrite() {
parent::onAfterWrite();
$urls = array();
$pages = Page::get();
foreach($pages as $page) {
$urls[] = $page->Link();
}
$sp = new FilesystemPublisher();
$sp->publishPages($urls);
}
Note the last 2 lines, and use the Page::get to specify the exact pages that need to be updated.
I'm programming a module in Joomla! 2.5. The module displays an article at a given position.
I need article attributes (i.e. show_title, link_title ecc.)
With this code I get article's specific attributes:
$db =& JFactory::getDBO();
$query = 'SELECT * FROM #__content WHERE id='.$id.' AND state=1';
$db->setQuery($query);
$item = $db->loadObject();
$attribs = json_decode($item->attribs, true);
If i var_dump the $attribs variable I get:
array(26) {
["show_title"]=>
string(0) ""
["link_titles"]=>
string(0) ""
[...]
}
The variable $attribs represents the article's specific attributes. When an element is set to "" means "use the global configuration".
I can get the global configuration with this query:
SELECT params from #__extensions where extension_id=22;
Where 22 is the id of the com_component extension. Then I can merge the results here with the results for the specific article.
BUT is there an easy way to achieve this? Does Joomla! have a specific class in the framework for this?
I would start with loading the model for articles:
// Get an instance of the generic articles model
$model = JModel::getInstance('Article',
'ContentModel',
array('ignore_request' => true));
The get the specific article...
$model->getItem($id)
To get a components global params I believe you can use:
$params = &JComponentHelper::getParams( 'COMPONENT_NAME' );
In your case you would need something like:
jimport('joomla.application.component.helper'); // load component helper first
$params = JComponentHelper::getParams('com_content');
I would suggest you look at the code of the article modules that ship with Joomla! 2.5.x as they do a lot of similar things to what you're trying to create. You can also have a read of this article, it's a bit dated but I think it still mostly holds true (except for jparams being replaced by jforms).