Forums / Developer / Help needed: Passing parameters from URL to PHP module

Help needed: Passing parameters from URL to PHP module

Author Message

Massimiliano Bariola

Friday 10 June 2005 2:35:39 am

Hi,

I'm currently trying to develop an extension module that will read data from an external database table according to certain URL parameters. To do so, I first tried my hand at customizing the eurofxref extension I found on a post on the forums.
If called with no parameters, the extension would display the whole list of currencies, while if called with a currency symbol (say DKK) it would have to show only the entry relevant to the selected currency.

I have trouble with getting the URL parameters accepted. So far, I was able to:

1) Pass the URL ordered parameter to the tpl file
2) Pass the URL ordered parameter to the php file using the $Params[array]

What I want to achieve, is to get the URL ordered parameter to be passed as an argument to the function fetchFX of the EuroFxRef class, so that I can restrict my data fetching at the php level.

this is the relevant part from my eurofxref/function_definition.php :

$FunctionList = array();

$FunctionList['fxref'] = array(
'name' => 'fxref',
'operation_types' => array( 'read' ),
'call_method' => array(
'include_file' => 'extension/eurofxref/modules/eurofxref/classes/eurofxref.php',
'class' => 'EuroFxRef',
'method' => 'fetchFX'),
'parameter_type' => 'standard',
'parameters' => array(
array(
'name' => 'CurrencySymbol',
'type' => 'string',
'required' => false))

this is the eurofxref/module.php ...

$Module = array( 'name' => 'Eurofxref' );

$ViewList = array();
$ViewList['overview'] = array(
'script' => 'overview.php',
'functions' => array( 'read' ),
'params' => array('CurrencySymbol')
);

$FunctionList['read'] = array();

this is the overview.tpl part .... (I tried various ways to pass the parameter through the fetch, all of them giving me an error :) )

{def $rates=fetch( 'eurofxref', 'fxref', array($currSymbol))}
{if ne( $currSymbol, '') }
<h1>Currency Symbol = {$currSymbol}</h1>
.......

here is the overview.php file ...

include_once( 'kernel/common/template.php' );

$tpl = & templateInit();
$tpl->setVariable( 'currSymbol', $Params['CurrencySymbol'] );

$Result = array();
$Result['content'] = &$tpl->fetch( 'design:eurofxref/overview.tpl' );
$Result['path'] = array( array( 'url' => '/eurofxref/overview',
'text' => 'Tassi di conversione con l\'Euro!' ) );

this is the class definition and how I thought the param to be passed in eurofxref/classes/euroxref.php

class EuroFxRef {

// static
function fetchFX($CurrencySymbol) {

.....

I am quite sure that the params _can_ be passed to the function, and the key to that must be in the function_definition.php. Yet, I can't get it to work after 2 days of head-banging.

Any nudge in the right direction?

thanks,

MB