Plugins and url parameters

From bemoko developer wiki

Viewed 1052 times, With a total of 2 Posts
Jump to: navigation, search

Threads 4
Posts 9
I am writing a plugin to retrieve data from a back-end system. There will be a url that the plugni uses to access the back-end system, but I want to pass a key into the plugin to retrieve the desired information.

I'm new to bemoko live and to plugins, so if this is a ridiculous question, please be patient with me.

I think that in the site-config.xml I describe my plugin and include a param for the url (without the key). Then on the page, I believe that I need to retrieve the key (perhaps a field or a url param) and supply it to the plugin's execute method. How do I do this?

Thanks,
Ian

Threads 4
Posts 9
At first, I just tried including the key as a param in the site-config.xml
 
  	< source name="supportpage" plugin="SupportPages.SupportPage">
  		<param name="url">http://mysite.net/service/sp</param>
  		<param name="key">84P2KU2</param>
  	</ source>

And in my plugin I created an initialise method like this:
 
	void initialise( Map map ) {
		url = map.url;
		key = map.key;
		supportpage = new XmlSlurper(false,false).parse(url + "&key=" + key)
	}


That worked perfectly, but when I needed to pull the key out of the config and make it dynamic from the URL, I had something like this:
 
  	< source name="supportpage" plugin="SupportPages.SupportPage">
  		<param name="url">http://mysite.net/service/sp</param>
  	</ source>

And I would call it with this URL: http://localhost:8080/live/supportpages/i?key=84P2KU2

In my page, using
${intent.key}
, I could see the value from the url parameter, so the value was available, but it never got passed to the plugin in the map. I also tried making an execute method that was similar to the initialise. Regardless, the getters in my plugin return nothing unless I include the key in the site-config.xml.

Any thoughts on what I'm doing wrong?

Thanks,
Ian

Threads 5
Posts 11
There are a couple of plugin methods of relevance here "void initialise(Map map)" and "void execute(Map map)". The initialise method is invoked as the plugin is loaded and the plugin parameters from the config are passed in. The execute method is invoked for each request and will have the intent parameters you want (i.e. map.key)

I've also written up an example on handling parameters with plugins @ http://bemoko.com/wiki/Plugins_and_URL_parameters. Which will give you a few more pointers.
Edited On 10:13:12 PM - Tue, Apr 20th 2010 by Admin


Forum >> bemokoLive Support >> General discussions




AWC's: 2.5.7 MediaWiki - Stand Alone Forum Extension
Forum theme style by: AWC Default