Plugin question

Have a programming question regarding your component, plug-in, extension or core hacks? Have an interesting tidbit, FAQ or programming tip you’d like to share? This is the place for you.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Post Reply
TheVigilante
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Tue Sep 11, 2007 8:24 am

Plugin question

Post by TheVigilante » Thu Nov 01, 2007 2:30 pm

I'm trying to execute some code just before any backend-components is displayed. What I want to do is check some user-parameters and redirect the user somewhere depending on these parameters. I know how to retrieve user parameter data, but the problem is that I can't find any plugin event which always triggers before an administration component loads, yet in which it's possible to redirect the user. I hoped anyone here knows how to do this?

User avatar
Pentacle
Joomla! Intern
Joomla! Intern
Posts: 61
Joined: Wed Oct 25, 2006 12:34 pm
Location: Turkey

Re: Plugin question

Post by Pentacle » Thu Nov 01, 2007 8:38 pm

onAfterInitialise should do the trick, I think. Use $mainframe->isAdmin() in the plugin to make sure that it's only enabled in administration.
My Joomla! 1.5 extensions - http://joomla.ercan.us
Progress is made by lazy men looking for easier ways to do things.

TheVigilante
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Tue Sep 11, 2007 8:24 am

Re: Plugin question

Post by TheVigilante » Fri Nov 02, 2007 9:15 am

I can't seem to get it to work. The redirection doesn't go. I tried the following:

function onAfterInitialise()
{
global $mainframe;
$mainframe->redirect('index.php?option=com_media');
}

When I do the same in the onLoginUser event, the redirection does work like this. I would expect the above snippet to cause a redirection to the com_media component when I open any other section...

Any idea's?

TheVigilante
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Tue Sep 11, 2007 8:24 am

Re: Plugin question

Post by TheVigilante » Fri Nov 02, 2007 2:14 pm

Apparently it does work when I put my plugin in the system plugin folder.

There is another problem however. When I redirect to another page I get a browser error. Yet when I disable the plugin and refresh the very same page, it does work.

The browser error is that the page incorrectly redirects in a way that will never end...
Last edited by TheVigilante on Fri Nov 02, 2007 2:46 pm, edited 1 time in total.

TheVigilante
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Tue Sep 11, 2007 8:24 am

Re: Plugin question

Post by TheVigilante » Fri Nov 02, 2007 2:48 pm

I think I already see what goes wrong. When the redirect is done, the plugin will be called again and redirects again etc, etc.

So I guess I got it solved!

User avatar
Pentacle
Joomla! Intern
Joomla! Intern
Posts: 61
Joined: Wed Oct 25, 2006 12:34 pm
Location: Turkey

Re: Plugin question

Post by Pentacle » Fri Nov 02, 2007 3:57 pm

TheVigilante wrote:I think I already see what goes wrong. When the redirect is done, the plugin will be called again and redirects again etc, etc.

So I guess I got it solved!


My first thought would be using a static variable. Can you explain how you got it solved please?
My Joomla! 1.5 extensions - http://joomla.ercan.us
Progress is made by lazy men looking for easier ways to do things.

TheVigilante
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Tue Sep 11, 2007 8:24 am

Re: Plugin question

Post by TheVigilante » Mon Nov 05, 2007 7:53 am

The plugin I'm trying to create works differently, this was just a test. Because of the redirect error I thought something didn't work, but now that I know it keeps executing the same redirect plugin over and over I know all works fine.


Post Reply