2014-02-12 2 views
0

Я пытаюсь выполнить mvc tutorial и установить code с помощью диспетчера расширений.Joomla master template

Все работает отлично и денди, но я пытаюсь выяснить, откуда взялась вся остальная страница. Шаблон только распечатывает «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 
{ 
} 

/компоненты /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 и оставить его в этом, но больше думал по пути представление для вывода данных и контроллер для извлечения данных.

ответ

0

Добавление &format=json изменяет тип jDocument (я думаю) и останавливает шаблон от обертывания в шаблоне «master». Если /components/com_helloworld/views/helloworld/view.json.php создаст необходимые заголовки.

Это работает, потому что у меня есть следующий файл: /public_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).