2014-02-14 28 views
1

在我正在處理的網站上,我從我的安裝中添加了/ public_html/libraries/joomla/document/json,因爲它不在那裏。該網站運行在1.5和本地我使用Joomla 2.5jDocument類在/ libraries/joomla/document/json被忽略

我的網址有添加&format=json,但可以看到響應標頭是text/html。也許2.5中的文件與1.5不兼容。它具有以下內容:

<?php 
defined('JPATH_PLATFORM') or die; 
class JDocumentJSON extends JDocument 
{ 
    protected $_name = 'joomla'; 
    public function __construct($options = array()) 
    { 
     parent::__construct($options); 
     $this->_mime = 'application/json'; 
     $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; 
    } 
} 
+0

你是說你只是從2.5中拉出一些文件並將其卡入1.5?不,這不會起作用。 – Elin

+0

@Elin謝謝你消除不起作用的東西。在一個不相關的主題上;你知道1.5的API參考嗎?它似乎不在Joomla網站上,或者它們隱藏起來很不錯。 – HMR

+0

@Elin發現它:http://docs.joomla.org/Framework/1.5重定向到另一個也被刪除的頁面。我爲所有那些花時間撰寫和翻譯這些文件的人感到抱歉。 – HMR

回答

1

檢查的1.5版本raw.php我發現只有很少的不同之處:

呈現不具有公共修飾符

也許在1.5更重要父::呈現先調用,所以現在的代碼如下所示:

<?php 
/** 
* @version  $Id: json.php 14401 2010-01-26 14:10:00Z louis $ 
* @package  Joomla.Framework 
* @subpackage Document 
* @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved. 
* @license  GNU/GPL, see LICENSE.php 
* Joomla! is free software. This version may have been modified pursuant 
* to the GNU General Public License, and as distributed it includes or 
* is derivative of works licensed under the GNU General Public License or 
* other free or open source software licenses. 
* See COPYRIGHT.php for copyright notices and details. 
*/ 

// Check to ensure this file is within the rest of the framework 
defined('JPATH_BASE') or die(); 

/** 
* DocumentJSON class, provides an easy interface to parse and display json output 
* 
* @package  Joomla.Framework 
* @subpackage Document 
* @since  1.5 
*/ 

class JDocumentJSON extends JDocument 
{ 

    /** 
    * Class constructore 
    * 
    * @access protected 
    * @param array $options Associative array of options 
    */ 
    protected $_name = 'joomla'; 
    function __construct($options = array()) 
    { 
     parent::__construct($options); 
     $this->_mime = 'application/json'; 
     $this->_type = 'json'; 
    } 

    /** 
    * Render the document. 
    * 
    * @access public 
    * @param boolean $cache  If true, cache the output 
    * @param array  $params  Associative array of attributes 
    * @return The rendered data 
    */ 
    function render($cache = false, $params = array()) 
    { 
     parent::render(); 
     JResponse::allowCache(false); 
     JResponse::setHeader('Content-disposition', 'attachment; filename="' . $this->getName() . '.json"', true); 
     return $this->getBuffer(); 
    } 
    public function getName() 
    { 
     return $this->_name; 
    } 
    public function setName($name = 'joomla') 
    { 
     $this->_name = $name; 
     return $this; 
    } 
} 

標題是正確設置現在