* zin: add renderJson method to send data to client as json.

This commit is contained in:
sunhao
2023-06-30 13:48:49 +08:00
parent 8ad8cdb2f0
commit 5bbeb611b7
+14
View File
@@ -103,3 +103,17 @@ function bind(string $name, string|array $callback, array $options = null): dire
return setData($data);
}
/**
* Render data to json.
*
* @param mixed $data data.
* @param int $flags json encode flags.
* @return void
*/
function renderJson(mixed $data, int $flags = 0)
{
ob_end_flush();
zin::$rendered = true;
echo json_encode($data, $flags);
}