忽略/libraries/joomla/document/json下的jDocument类

忽略/libraries/joomla/document/json下的jDocument类,json,joomla,Json,Joomla,在我正在开发的一个网站上,我从安装中添加了/public_html/libraries/joomla/document/json,因为它不在那里。该网站运行于1.5版本,我在本地使用的是Joomla 2.5 我的url添加了&format=json,但可以看到响应头是text/html。可能2.5版本的文件与1.5版本不兼容。它有以下内容: <?php defined('JPATH_PLATFORM') or die; class JDocumentJSON extends JDocume

在我正在开发的一个网站上,我从安装中添加了/public_html/libraries/joomla/document/json,因为它不在那里。该网站运行于1.5版本,我在本地使用的是Joomla 2.5

我的url添加了
&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;
    }
}

查看1.5版本的raw.php时,我注意到只有很小的差异:

渲染没有公共修改器

在1.5中可能更重要的是,首先调用parent::render,因此代码现在看起来像:

<?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;
    }
}

你是说你刚刚从2.5中提取了一些文件,并将其粘贴到1.5中?不,这是行不通的。@Elin谢谢你消除了不起作用的东西。在一个无关的主题上;你知道API对1.5的引用吗?它似乎不在Joomla网站上,或者他们隐藏得很好。@Elin找到了它:重定向到另一个也被删除的页面。我为那些花时间编写和翻译这些文件的人感到抱歉。