问题
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