Build a component view for json formatted output.
http://localhost/joomla/index.php?option=com_testcomponent&view=json&format=json
<?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);
}
}
<?= $this->json; ?>
{"key1":"value1","key2":"value2","key3":"value3","key4":"value4"}
<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 />
MS Windows 11
XAMPP for Windows 8.1.12
Apache/2.4.54 (Win64)
PHP Version 8.1.12
Debug mode is turned on, but nothing populates in everything.php
Labels |
Removed:
?
|
Labels |
Added:
No Code Attached Yet
|
This is coming from recent changes in debug plugin. When Track Request History
option is disabled, an unlimited number of request data is stored in the session until a HTML page is opened.
Confirmed, enabling Track Request History
removes the error message.
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
I cannot reproduce the issue with your code since JsonView doesnt apply any template code. So the output is always empty... tmpl\json\json.php is never called. parent::display just puts this->_output into the documents buffer. $this->json is not used.
I can think of a problem where the session data is growing too much, but cannot reproduce the issue right now.
Please post the complete code with this issue - Thank you
Labels |
Added:
Information Required
|
I have found another thing which happens with PHP 8 which happens when the "Track Request History" option in the "Debug" system plugin is disabled and disappears when that option is enabled. See #39403 . It seems they have the same root cause, but I wanted the symptoms to be documented and so created that other issue.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-12-30 09:55:31 |
Closed_By | ⇒ | richard67 |
I am seeing the same messages, intermittently, about failing to write the session when invoking a controller via JS that passes to and is returned JSON.
url = 'index.php?option=com_mycomponent&task=mycontroller.incoming&format=json';
my controller does almost nothing
Reloading the page resolves the issue for awhile but its return is seemingly random.
I don't have anymore diagnostics than already supplied at this stage.
PHP Version 8.0.23
Web Server Apache/2.4.54 (Win64) OpenSSL/1.1.1q PHP/8.0.23
WebServer to PHP Interface apache2handler
Joomla! Version Joomla! 4.2.5 Stable [ Uaminifu ] 8-November-2022 15:00 GMT
Running on a local LAMP stack.
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39341.