简体   繁体   中英

Slim 3 framework - RenderView

I would like to render view and return it with JSON in my controler like the renderView in Symfony.

//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]);
}

I don't get what you try to achive, but if you want to return the rendered content within a json response then try this:

// ...

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM