简体   繁体   English

Slim 3框架-RenderView

[英]Slim 3 framework - RenderView

I would like to render view and return it with JSON in my controler like the renderView in Symfony. 我想渲染视图并在我的控制器中使用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]);
}

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: 我没有获得尝试达到的目标,但是如果您想在json响应中返回渲染的内容,请尝试以下操作:

// ...

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

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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