Symfony - RuntimeException:注释“@FOS \ RestBundle \ Controller \ Annotations \ View”的未知键“class”

时间:2016-11-01 00:30:18

标签: web-services rest symfony doctrine fosrestbundle

我想用symfony2创建Web服务休息, 我安装了SerializerBundle& FOSRestBundle 当我尝试指挥官时php app/console router:debug  为此目的,但我收到以下错误。

[RuntimeException]                                                                 
  Unknown key "class" for annotation "@FOS\RestBundle\Controller\Annotations\View". 

班级视图存在。

<?php

namespace Sdz\AdminBundle\Controller;

use FOS\RestBundle\Controller\Annotations\View;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;

use Sdz\VoyageBundle\Entity\Promo;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class RestpromoAction extends Controller
{    
    /**
     * @View("restpromo",class="SdzVoyageBundle:Promo")
     * @ParamConverter()
     */
    public function getPromorestAction(Promo $entitysPromo)
    {
        return array('restpromo'=>$entitysPromo);
    }
}

如何解决此问题?

1 个答案:

答案 0 :(得分:1)

您已将“class”参数添加到@View而不是@ParamConverter

这是错误的一行:

@View("restpromo",class="SdzVoyageBundle:Promo")

将变量名称和相应的类添加到@ParamConverter以解决您的问题。

use FOS\RestBundle\Controller\Annotations as FOSRest;
use Sensio\Bundle\FrameworkExtraBundle\Configuration as SensioFrameworkExtra;

/**
 * @FOSRest\View()
 * @SensioFrameworkExtra\ParamConverter(
 *     "promo",
 *     class="SdzVoyageBundle:Promo"
 * )
 */
public function getPromorestAction(Promo $promo)
{
    return array(
        'restpromo' => $promo
    );
}