Forums / Developer / Module Development - Please help!!!

Module Development - Please help!!!

Author Message

Tristan Koen

Monday 10 November 2003 11:16:32 pm

Hi

I am busy writing a new module and have run into an issue that I just can't solve. I am hoping that someone on this forum can give me a hint as to where I'm going wrong.

I have based my code on the Module Tutorial in the documentation section. The difference is that I get my data from a SOAP datasource rather than the database.

The problem seems to stem from my use of the templating system.

My code is as follows:

BEGIN list.php------------------------------------------>
<?php

$Module= &$Params['Module'];
$viewParameters = array('upc' => $Params['upc']);

include_once( "kernel/common/template.php");
$tpl = &templateInit();
$tpl->setVariable('view_parameters', $viewParameters);

$Result=array();
$Result['content'] = $tpl->fetch("design:mymodule/product.tpl");
$Result['path'] = array(array('url' => '/mymodule/product',
'text' => 'Products'));

?>

END mymodule.php------------------------------------------>

I then have another file called function_definition.php that looks as follows:

BEGIN function_definition.php------------------------------------------>

<?php

$FunctionList = array();
$FunctionList['list'] = array('name' => 'list',
'operation_types' => array('read'),
'call_method' => array('include_file' => 'extension/warehouse/modules/mymodule/productfunctioncollection.php',
'class' => 'ProductFunctionCollection',
'method' => 'fetchItem'),
'parameter_type' => 'standard',
'parameters' => array(array('name' => 'upc',
'required' => true,
'default' => false)));

?>

END function_definition.php------------------------------------------>

This part appears to be correct and works as I would expect it to.

I then have a simple 'test' file called productfunctioncollection.php. It just returns a dummy result array (for test purposes). It looks as follows:

BEGIN productfunctioncollection.php------------------------------------------>

<?php

class ProductFunctionCollection
{
function ProductFunctionCollection()
{
}

function &fetchItem($upc)
{
return array('result' => &$upc);
}
}

?>

END productfunctioncollection.php------------------------------------------>

I then have a simple template file mymodule/product.tpl that looks as follows:

BEGIN product.tpl------------------------------------------>
View Parameters: {$view_parameters.upc} <br />
{let test = fetch('mymodule','list',hash('upc','123')}
{$test}
{/let}
END
mymodule.php------------------------------------------>

No matter what I do, the value of $test is always 1, instead of being an array. The value for the upc is correct.

If I put print() statements in the code, it all executes correctly. The problem seems to be where the array with the 'result' element is returned to the templeting system. I have tried everyting and cannot get this to work.

I have to assume that the array I am returning in &fetchItem() needs some other elements?

I anyone can give me a hand here, I will really appreciate it. I have been stuck on this problem for 2 days now and am getting desperate.

Thanks

Paul Forsyth

Tuesday 11 November 2003 2:17:06 am

Declare the type of the variable being input into the function:

'parameters' => array(array('name' => 'upc',
'type' => 'integer',
'required' => true,
'default' => false)));

Do you want to return an array from the integer you input? '123' becomes '1,2,3'? From your code it seems like you are simply passing a number to the php and back again.

paul

eZ debug

Timing: Jan 18 2025 15:04:15
Script start
Timing: Jan 18 2025 15:04:15
Module start 'content'
Timing: Jan 18 2025 15:04:15
Module end 'content'
Timing: Jan 18 2025 15:04:15
Script end

Main resources:

Total runtime0.0183 sec
Peak memory usage2,048.0000 KB
Database Queries4

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0065 587.7109180.8359
Module start 'content' 0.00650.0059 768.546993.7734
Module end 'content' 0.01240.0058 862.320370.7031
Script end 0.0182  933.0234 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002011.1993120.0002
Check MTime0.00095.1029120.0001
Mysql Total
Database connection0.00115.900810.0011
Mysqli_queries0.002312.692140.0006
Looping result0.00000.097820.0000
Template Total0.005529.810.0055
Template load0.00084.134210.0008
Template processing0.004725.647610.0047
Override
Cache load0.00052.997410.0005
General
dbfile0.002815.3988100.0003
String conversion0.00000.039130.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs