Help needed: passing URL parameters as function arguments

Author Message

Massimiliano Bariola

Friday 10 June 2005 2:38:44 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 :) ) basically, I'd want either to pass the parameter either through the fetch or through the URL

{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

Massimiliano Bariola

Friday 10 June 2005 5:13:06 am

Seems like I figured it out.
Parameters from URL are passed to the view php file in the $Params array.

the view file passes them to the relevant template via $tpl->setVariable.

the template, in turn passes them to the php class and method through the parameters of the fetch function.

Now it "works". maybe there is a more straightforward approach which I didn't notice?

TIA

Massimiliano Bariola

Friday 10 June 2005 5:58:57 am

... then I rewrote my code with my newfound knowledge, only to discover it won't work!

<headbanging />

I discovered it's some kind of capitalization issue. parameter names in a fetch are sensitive to their first letter's case. but not to the case of other letters.

e.g. CurrencySymbol != currencySymbol
but
currencySymbol == cUrrENCYSymbol == cURRENCYSYMBOL.

I have been browsing the documentation but didn't find anything mentioning it (except for case-sensitiveness of $variables).

the code line in the template:

{def $rates=fetch( 'eurofxref', 'fxref' , hash(cURRENCYSYMBOL, $currSymbol))}

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.