0

我有一个由学说生成的简单的 crud 控制器

<?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 模板。为什么会这样?

我正在使用 Symfonyv2.3.4v2.3.5

4

1 回答 1

1

FOS\RestBundle\FOSRestBundle当我从AppKernel.php一切正常工作中删除时,捆绑包正在产生冲突

于 2013-09-28T17:02:45.953 回答