1

I really hope someone can help me.

I need to be able to serve banners in categories which are dependant on a session variable - and can't find a component which does that. So I'd like to extend the Joomla Banner component in order to select banners based on a session variable which contains the category path.

The correct session variable is being stored correctly.

In order to do this I added an option in the banners module .xml to allow for a session variable and the name of the session variable. This is being stored correctly in the module table within the params field along with the other module parameters.

Then I started on the

components > banners > com_banners > models > banners.php

by adding two lines of code in getListQuery where the SQL is assembled. They are:

$sess_vars  = $this->getState('filter.sess_vars');
$sess_vars_name = $this->getState('filter.sess_vars_name');

But both variables contain nothing even though the ones the component already has can be retrieved fine. Without a doubt I need to change something somewhere else as well - but just can't figure out what to do.

Any help would be greatly appreciated.

1
  • Can you add what code you used to store the session variable? Feb 7, 2013 at 22:51

1 Answer 1

1
  1. The first thing to do is not hack the core files, hacking the core prevents you from using the built-in update feature to apply the regular bug fixes and security patches released by Joomla! (e.g. the recently released 2.5.9 version).

  2. Rather make a copy of them and modify it so it's called something else like com_mybanners. Apart from the folder name and the entry point file (i.e. banners.php becomes mybanners.php) you will also want to update the components banners.xml to mybanners.php.

    (You will need to duplicate and modify both the front end /components/com_banners/ and /administrator/components/mybanners.php.)

  3. Because of the way Banners work (i.e. banners are displayed in a module) you will also need to duplicate and modify /modules/mod_banners/,/modules/mod_banners/mod_banners.php and /modules/mod_banners/mod_banners.xml. Changing mod_banners to mod_mybanners in each location.

  4. In Joomla! components the state is usually populated when JModel is instantiated, however, in this case the component is really about managing banners and recording clicks the display is handled by mod_banners. So, you will want to add some code to mod_mybanners.php to use the session variables you want to act on.

    Normally when a models state is queried you will collect the variables via JInput and add them to your object's state e.g.

protected function populateState()
{
    $jApp = JFactory::getApplication('site');

    // Load state from the request.
    $pk = $jApp->input->get('id',0,'INT');
    $this->setState('myItem.id', $pk);

    $offset = $jApp->input->get('limitstart',0,'INT');
    $this->setState('list.offset', $offset);

    // Load the parameters.
    $params = $app->getParams();
    $this->setState('params', $params);

    // Get the user permissions
    $user       = JFactory::getUser();
    if ((!$user->authorise('core.edit.state', 'com_mycomponent')) &&  (!$user->authorise('core.edit', 'com_mycomponent')))
    {
        $this->setState('filter.published', 1);
        $this->setState('filter.archived', 2);
    }
}

The populateState() method is called when a state is read by the getState method.

This means you will have to change your copy of /components/com_banners/models/banner.php to capture your variables into the objects state similar to my example above.

From there it's all your own code.

You can find all of this information in the Developing a Model-View-Controller tutorial on the Joomla Doc's site

1
  • 1
    you're welcome — it's a good idea to mark an answer as "Accepted" if it solves your problem or to upvote it if it helps (or even both it the answer merits it).
    – Craig
    Feb 23, 2013 at 5:00

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.