How to return both integer parameter and render template as response in Symfony2

风流意气都作罢 提交于 2019-12-24 14:15:48

问题


I want to return on my ajax request rendered view, and some integer values, but I dont know how I can do this. I try to encode array with content into json, but then in success callback function I getting the array where I can see the field with integer, and "header" param that empty. So how can I return both integer parameter and render response in Symfony2 ?


回答1:


I assume from your question that you are wanting to return something like..

array(
    'html'      => **your html**,
    'integer'   => **your integer**,
);

If that is correct you could do the following...

// ->renderResponse render the string and creates a response object for you to return
// ->render just renders the string into a variable
$html = $this->container->get('templating')->render(**template**, **parameters**);
$integer = **your integer**;

// Return a JSON object with the correct headers and what not
return new JsonResponse::create(array(
    'html'      => $html,
    'integer'   => $integer,
));


来源:https://stackoverflow.com/questions/28211290/how-to-return-both-integer-parameter-and-render-template-as-response-in-symfony2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!