我正在构建一个Joomla模块,它最终将从外部数据源中提取数据。现在,当我学习时,我将其设置为仅将字符串“This bit working works”打印到模块位置。不过,我一直有问题让它正常工作。这里是我的代码:Joomla 1.5模块输出返回语句
mod_ucr.php:
<?php
/**
* UniversalContentRepository Module Entry Point
*
* @package UniversalContentRepository
* @subpackage Modules
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
// Include the syndicate functions only once
require_once(dirname(__FILE__).DS.'helper.php');
$helper = new modUCRHelper();
$content = $helper->getSnippetContent();
require(JModuleHelper::getLayoutPath('mod_ucr'));
?>
mod_ucr.xml
<?xml version="1.0" encoding="utf-8"?>
<install type="module" version="1.5.0">
<name>Universal Content Repository</name>
<author>Brendon Dugan</author>
<version>1.5.0</version>
<description>A module to allow the insertion of UCR Snippets into a Joomla site.</description>
<files>
<filename>mod_ucr.xml</filename>
<filename module="mod_ucr">mod_ucr.php</filename>
<filename>index.html</filename>
<filename>helper.php</filename>
<filename>tmpl/default.php</filename>
<filename>tmpl/index.html</filename>
</files>
<params>
</params>
</install>
helper.php:
<?php
class modUCRHelper
{
function __construct(){
}
public function getSnippetContent($id = 0){
$content = "This bit works correctly, ID = $id";
return $content;
}
}
?>
TMPL /如default.php:
<?php // no direct access
defined('_JEXEC') or die('Restricted access');
echo $content;
?>
这里我们将变量$ content设置为助手类的getSnippetContent()方法的输出。此方法当前是:
function getSnippetContent($id = 0){
$output = "This bit works correctly";
return $output;
}
它只是输出我想要打印的字符串。在我的模板,我应该能够呼应了这样的内容:
<?php // no direct access
defined('_JEXEC') or die('Restricted access');
echo $content;
?>
但是模块输出的反而是
"This bit works correctlyThis bit works correctly"
如果我注释掉echo语句,字符串依然回荡一次,这表明回报声明本身就是回声。
我修改了“Hello World!”中的代码。例子位于in the Joomla documentation。有任何想法吗?
你可以发布模块的所有(我相信4)文件吗? – 2012-01-03 19:47:23