-
- 209 Posts
Where can I find the explanation of the events for the plug-ins? I read a simple example in the MODx example, but it uses only an event and I cannot find anywhere an explanation about when the event happends and which variables are available, what can you modify, etc.
Do I miss something?
Daniele "MadMage" Calisi
-
- 3,250 Posts
Documentation for plugin events is not yet complete but most of the events do exactly what their name implies.
For example, ondocformrender fires right when the Edit/Create document form comes up.
-
- 209 Posts
ok, but... I need something that redirects the browser in another page...
I need to check a field of the site_content table of the current document and then do a redirect...
I know how to do the redirect, but, as you know, it has to happend in the header part, so BEFORE anything is sent to the browser
So, I need an event that happends when I have the $modx->documentObject[] stuff and BEFORE it writes something...
which event should I use?
Daniele "MadMage" Calisi
I think a snippet would do the job; have it check with $modx->documentObject[’field’] and redirect if it finds what it’s looking for. Just drop the snippet into your template somewhere, probably in the head.
I suppose you can use the same thing in a plugin; I’m not exactly sure at what system event the documentObject array is available. You can always do it like I do; trial and error! It will be one of the top group of events for sure. Try "onWebPagePreRender"; that won’t be the most efficient since it occurs after all the parsing is done, and you probably would like to do it as soon as the array is available.
-
- 1,495 Posts
Or you can use onWebPageInit.
I believe that MODx is using cache from PHP, which doesn’t send the ouput until the last execution of document parser.
You might wanna give it a try.
-
- 1,732 Posts
Here’s some more info on event calling order:
1. OnWebPageInit - Very first event when a page is initialized.
2. OnLoadWebPageCache - If page is cached then this event is next. The cached documentObject is available here.
3. OnLoadWebDocument - if page is not (yet) cached then this event is triggered next. The documentObject is available here
4. OnWebPagePrerender - This is the final event that’s triggered before the page is sent to the browser.
-
- 209 Posts
I think that I could redirect simply using the header Location... but the redirection enver occurs... I made a plug-in for the OnWebPagePrerender event with a simple
header("Location: http://xxxxx");
return;
but it doesn’t work...
Daniele "MadMage" Calisi
-
- 1,732 Posts
can you display the source of your plugin?
I always add a bunch of troubleshooting "echo" statements to my code while developing. If you’re looking for a certain value in the documentContent, put an echo ’found it’; in the conditional block. If you know it’s there, but it’s just not finding it, you can refine the conditional to return more information until you figure out why.
This way you can narrow down the issues until you find exactly where the problem is. If it’s finding your conditional, but the redirect isn’t working, then you know it’s a problem with your redirect code.