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

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 18 2025 18:31:36
Script start
Timing: Jan 18 2025 18:31:36
Module start 'layout'
Timing: Jan 18 2025 18:31:36
Module start 'content'
Timing: Jan 18 2025 18:31:38
Module end 'content'
Timing: Jan 18 2025 18:31:38
Script end

Main resources:

Total runtime1.7872 sec
Peak memory usage4,096.0000 KB
Database Queries54

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0086 587.9141152.6250
Module start 'layout' 0.00860.0036 740.539139.4453
Module start 'content' 0.01221.7734 779.9844476.5703
Module end 'content' 1.78560.0015 1,256.554712.1563
Script end 1.7872  1,268.7109 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00360.2021160.0002
Check MTime0.00170.0968160.0001
Mysql Total
Database connection0.00100.055310.0010
Mysqli_queries1.717096.0708540.0318
Looping result0.00060.0325520.0000
Template Total1.739597.320.8698
Template load0.00200.113020.0010
Template processing1.737597.217220.8687
Template load and register function0.00020.013310.0002
states
state_id_array0.00140.075610.0014
state_identifier_array0.00140.080920.0007
Override
Cache load0.00180.0983740.0000
Sytem overhead
Fetch class attribute can translate value0.00060.035620.0003
Fetch class attribute name0.00290.163420.0015
XML
Image XML parsing0.00030.015920.0001
class_abstraction
Instantiating content class attribute0.00000.000620.0000
General
dbfile0.00070.0414100.0001
String conversion0.00000.000740.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
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
10content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
8content/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: 22
 Number of unique templates used: 5

Time used to render debug report: 0.0001 secs