Return 在 Nette PHP 框架中不使用模板的字符串

Return string without using a template in Nette PHP framework

在不加载模板的情况下,在 nette php 框架中 return json 字符串或屏幕上的简单文本的最佳方法是什么?

您可以在演示者中使用方法 sendJson($data)

function renderDefault()
{
    $data = ['hello' => 'world'];
    $this->sendJson($data);
}

将输出 {"hello":"world"}application/json Content-Type