Search code examples
phpnette

Return string without using a template in Nette PHP framework


What is the best way to return a json string or a simple text on screen in nette php framework without loading the template?


Solution

  • You can use method sendJson($data) in your presenter.

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

    Will output {"hello":"world"} with application/json Content-Type