从symfony 2控制器动作返回数组

3 php symfony

I need to return $items array from 'http://localhost:8000/cart/viewall'
controller action. But all i get is this error.
Run Code Online (Sandbox Code Playgroud)

Response内容必须是实现__toString(),"array"的字符串或对象.

这是我的代码,

 /**
 * @Route("/cart/viewall")
 * @Template()
 */
public function viewallAction() {
    $items = array(1 => 'item 1', 2 => 'item 2');        
    return new Response($items);
}     
Run Code Online (Sandbox Code Playgroud)

如果有人能提供解决方案,那将会很有帮助.

cha*_*asr 7

JsonResponse改用.

示例:

$items = array(1 => 'item 1', 2 => 'item 2');
return new JsonResponse($items);
Run Code Online (Sandbox Code Playgroud)

请参阅http://symfony.com/doc/current/components/http_foundation/introduction.html