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
|