Slim 3框架-RenderView

时间:2019-01-25 17:37:57

标签: php twig slim

我想渲染视图并在其控制器中使用JSON返回它,例如Symfony中的renderView。

//use Slim\Container;
protected $ci;

    public function __construct(Container $ci)
    {
        $this->ci = $ci;
    }
public function AnalyseFacture(Request $request, Response $response,$args){
    $db    = $this->ci->dbLeak;
    $clients = self::RecuperationFacture($db);
    $data = $this->ci->view->render($response, 'envoiefacture/resultat-ajax.twig', ['liste' => $clients]);


    return $response->withJson(['data' => $data]);
}

1 个答案:

答案 0 :(得分:0)

我不知道您尝试达到的目标,但是如果您想在json响应中返回渲染的内容,请尝试以下操作:

// ...

$this->ci->view->render($response, 'envoiefacture/resultat-ajax.twig', ['liste' => $clients]);

$data = (string)$response->getBody();

return $response->withJson(['data' => $data]);