我正在構建一個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