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.

eZ debug

Timing: Jan 19 2025 03:28:21
Script start
Timing: Jan 19 2025 03:28:21
Module start 'layout'
Timing: Jan 19 2025 03:28:21
Module start 'content'
Timing: Jan 19 2025 03:28:22
Module end 'content'
Timing: Jan 19 2025 03:28:22
Script end

Main resources:

Total runtime1.3249 sec
Peak memory usage4,096.0000 KB
Database Queries55

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0055 589.4141152.6563
Module start 'layout' 0.00550.0037 742.070339.5078
Module start 'content' 0.00921.3142 781.5781495.2813
Module end 'content' 1.32340.0015 1,276.859412.0938
Script end 1.3249  1,288.9531 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00370.2780160.0002
Check MTime0.00180.1346160.0001
Mysql Total
Database connection0.00070.051910.0007
Mysqli_queries1.249894.3323550.0227
Looping result0.00050.0361530.0000
Template Total1.291297.520.6456
Template load0.00190.146720.0010
Template processing1.289297.305020.6446
Template load and register function0.00010.006610.0001
states
state_id_array0.00070.055710.0007
state_identifier_array0.00250.187320.0012
Override
Cache load0.00180.1345760.0000
Sytem overhead
Fetch class attribute can translate value0.00060.043010.0006
Fetch class attribute name0.00160.123640.0004
XML
Image XML parsing0.00050.040210.0005
class_abstraction
Instantiating content class attribute0.00000.001260.0000
General
dbfile0.00220.1676170.0001
String conversion0.00000.000840.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
12content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
10content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 30
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs