Page 1 of 1

Plugin question

Posted: Thu Nov 01, 2007 2:30 pm
by TheVigilante
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?

Re: Plugin question

Posted: Thu Nov 01, 2007 8:38 pm
by Pentacle
onAfterInitialise should do the trick, I think. Use $mainframe->isAdmin() in the plugin to make sure that it's only enabled in administration.

Re: Plugin question

Posted: Fri Nov 02, 2007 9:15 am
by TheVigilante
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?

Re: Plugin question

Posted: Fri Nov 02, 2007 2:14 pm
by TheVigilante
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...

Re: Plugin question

Posted: Fri Nov 02, 2007 2:48 pm
by TheVigilante
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!

Re: Plugin question

Posted: Fri Nov 02, 2007 3:57 pm
by Pentacle
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?

Re: Plugin question

Posted: Mon Nov 05, 2007 7:53 am
by TheVigilante
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.