Model view controller 主模板Joomla

Model view controller 主模板Joomla,model-view-controller,joomla2.5,Model View Controller,Joomla2.5,我正在尝试遵循,并安装了扩展管理器 这一切都很好,但我正试图找出所有其余的页面从何而来。该模板只打印出Hello World,但页面包含菜单和全部 有没有办法只打印Hello World?这表明我可以编辑一些未指定内容的文件并将其打印出JSON,但当输出被某种母版页模板包围时,它将是无效的JSON 安装插件后,我有以下文件: /components/com_helloworld/helloworld.php <?php // No direct access to this file d

我正在尝试遵循,并安装了扩展管理器

这一切都很好,但我正试图找出所有其余的页面从何而来。该模板只打印出Hello World,但页面包含菜单和全部

有没有办法只打印Hello World?这表明我可以编辑一些未指定内容的文件并将其打印出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中输出一些东西,并将其保留在那里,但在视图生成输出和控制器获取数据的过程中,我考虑了更多。

Adding&format=json更改了我猜想的jDocument类型,并阻止了将模板包装到主模板中。拥有/components/com_helloworld/views/helloworld/view.json.php将生成所需的头文件

这是因为我有以下文件:/public\u html/libraries/joomla/document/json/json.php

包含以下内容:

<?php
defined('JPATH_PLATFORM') or die;
class JDocumentJSON extends JDocument
{
    protected $_name = 'joomla';
    public function __construct($options = array())
    {
        parent::__construct($options);

        // Set mime type
        $this->_mime = 'application/json';

        // Set document type
        $this->_type = 'json';
    }
    public function render($cache = false, $params = array())
    {
        JResponse::allowCache(false);
        JResponse::setHeader('Content-disposition', 'attachment; filename="' . $this->getName() . '.json"', true);

        parent::render();

        return $this->getBuffer();
    }
    public function getName()
    {
        return $this->_name;
    }
    public function setName($name = 'joomla')
    {
        $this->_name = $name;

        return $this;
    }
}
我猜你基本上可以在那里添加任何文件,并输出任何类型的响应,尽管基本功能似乎已经存在,也许我会添加jsonp