2013-09-28 72 views
0

我有一個簡單的CRUD控制器通過教義產生@Route(默認= { 「_格式」= 「JSON」}返回HTML

<?php 

namespace MyBundle\Controller; 

use Symfony\Component\HttpFoundation\Request; 
use Symfony\Bundle\FrameworkBundle\Controller\Controller; 
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; 
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; 
use MyBundle\Entity\MyEntity; 
use MyBundle\Form\MyEntityType; 

/** 
* PsaEventualidadContrato controller. 
* 
* @Route("/my") 
*/ 
class MyController extends Controller 
{ 
    //... 
    /** 
    * Displays a form to create a new MyEntity entity. 
    * 
    * @Route("/new.{_format}", name="my_new", defaults={"_format"="json"}) 
    * @Method("GET") 
    * @Template() 
    */ 
    public function newAction() 
    { 
     $entity = new MyEntity(); 
     $form = $this->createCreateForm($entity); 

     return array(
      'entity' => $entity, 
      'form' => $form->createView(), 
     ); 
    } 
    //... 
} 

當我去http://myhost/app_dev.php/my/new.jsondev.log我可以看到

[2013-09-28 11:29:13] request.INFO: Matched route "eventualidad_new" (parameters: "_format": "json", "_controller": "MyBundle\Controller\MyController::newAction", "_route": "my_new") [] [] 

但瀏覽器呈現HTML模板。爲什麼出現這種情況?

我使用的Symfony v2.3.4v2.3.5

回答

1

捆綁FOS\RestBundle\FOSRestBundle正在創建一個衝突,當我從AppKernel.php刪除一切正常