【发布时间】:2014-02-12 13:03:42
【问题描述】:
我正在尝试关注mvc tutorial 并使用扩展管理器安装code。
这一切都很好而且花花公子,但我正试图弄清楚页面的所有其余部分来自哪里。模板只打印出“Hello World”,但页面包含菜单和所有内容。
有没有办法只打印出“Hello World”? following 表明我可以编辑一些文件(未指定什么)并让它打印出 JSON,但当输出被某种母版页模板包围时,它将是无效的 JSON。
安装插件后,我有以下文件:
/components/com_helloworld/helloworld.php
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import joomla controller library
jimport('joomla.application.component.controller');
// Get an instance of the controller prefixed by HelloWorld
$controller = JController::getInstance('HelloWorld');
// Perform the Request task
$controller->execute(JRequest::getCmd('task'));
// Redirect if set by the controller
$controller->redirect();
/components/com_helloworld/controller.php
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla controller library
jimport('joomla.application.component.controller');
/**
* Hello World Component Controller
*/
class HelloWorldController extends JController
{
}
/components/com_helloworld/views/helloworld/view.html.php
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla view library
jimport('joomla.application.component.view');
/**
* HTML View class for the HelloWorld Component
*/
class HelloWorldViewHelloWorld extends JView
{
// Overwriting JView display method
function display($tpl = null)
{
// Assign data to the view
$this->msg = 'Hello World';
// Display the view
parent::display($tpl);
}
}
/components/com_helloworld/views/helloworld/tmpl/default.php
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
?>
<h1><?php echo $this->msg; ?></h1>
我可以在 /components/com_helloworld/helloworld.php 中输出一些内容并将其保留在该位置,但我在考虑更多的视图以生成输出和控制器以获取数据。
【问题讨论】:
标签: model-view-controller joomla2.5