Skip to content

Component build json output #39341

@JamesShaver

Description

@JamesShaver

Steps to reproduce the issue

Build a component view for json formatted output.

URL:

http://localhost/joomla/index.php?option=com_testcomponent&view=json&format=json

site\src\View\Json\JsonView.php:
<?php

namespace Joomla\Component\Testcomponent\Site\View\Json;

use Joomla\CMS\MVC\View\JsonView as BaseJsonView;

class JsonView extends BaseJsonView
{
    public $json;
    
    public function display($tpl = null)
    {
        $array = [
            'key1' => 'value1',
            'key2' => 'value2',
            'key3' => 'value3',
            'key4' => 'value4'
        ];
        $this->json = json_encode($array);
        
        parent::display($tpl);
    }
}
site\tmpl\json\json.php:
<?= $this->json; ?>

Expected result

{"key1":"value1","key2":"value2","key3":"value3","key4":"value4"}

Actual result

<br />
<b>Warning</b>:  session_write_close(): Failed to write session data using user defined save handler. (session.save_path: \Users\username\OneDrive\Documents\Development\xampp\tmp) in <b>C:\Users\username\OneDrive\Documents\Development\xampp\htdocs\joomla\libraries\vendor\joomla\session\src\Storage\NativeStorage.php</b> on line <b>114</b><br />

System information (as much as possible)

MS Windows 11
XAMPP for Windows 8.1.12
Apache/2.4.54 (Win64)
PHP Version 8.1.12

Additional comments

Debug mode is turned on, but nothing populates in everything.php

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions