결국 외부 데이터 소스에서 데이터를 가져 오는 Joomla 모듈을 구축 중입니다. 지금 내가 배우는 동안, 단순히 "이 비트가 올바르게 작동합니다"라는 문자열을 모듈 위치에 인쇄하도록 설정했습니다. 그러나, 제대로 작동하도록 문제가 발생했습니다. 여기 내 코드입니다 :Joomla 1.5 모듈 출력 return 문
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"
, 문자열이 여전히 한 번 감동입니다, return 문 자체가 울리고 있음을 나타냅니다.
"Hello World!"의 코드를 수정했습니다. 예 : in the Joomla documentation. 어떤 아이디어?
모듈에 대한 모든 (4 가지로 생각하는) 파일을 게시 할 수 있습니까? –