1

我刚刚安装了 FOSRestBundle 运行缓存时出现此错误:清除

[Symfony\Component\Config\Exception\FileLoaderLoadException]

  Cannot import resource "/Users/gitek/www/hotel/src/Gitek/RegistroBundle/Resources/config/routing_incidencia.yml" from "/Users/gitek/www/hotel/app/config/routing.yml".  


  [RuntimeException]                                                                                                                                                                                                                                                                                         

  The autoloader expected class "Gitek\RegistroBundle\Controller\IncidenciaController" to be defined in file "/Users/gitek/www/hotel/app/../src/Gitek/RegistroBundle/Controller/IncidenciaController.php". The file was found but the class was not in it, the class name or namespace probably has a typo.  

这是我的控制器:

<?php

namespace Gitek\RegistroBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use FOS\RestBundle\View\View;
use Gitek\RegistroBundle\Entity\Registro;
use Gitek\HotelBundle\Entity\Incidencia;

class UsuarioController extends Controller
{

    public function putIncidenciaAction($registro_id, $incidencia_id)
    {
        $em         = $this->get('doctrine')->getEntityManager();
        $registro   = $em->getRepository('RegistroBundle:Registro')->find($registro_id);
        $incidencia = $em->getRepository('HotelBundle:Incidencia')->find($incidencia_id);

        $request = $this->getRequest();

        $registro->setIncidencia($incidencia);
        $em->persist($registro);
        $em->flush();

        $view = View::create();
        $view->setData($registro);

        return $view;
    } // "put_incidencia"     [PUT] /incidencia/{registro_id, incidencia_id}

}

这是我的#app/config/routing.yml

incidencias:
    resource: "@RegistroBundle/Resources/config/routing_incidencia.yml"
    prefix:   /
    type: rest

这是我的#src/Gitek/RegistroBundle/Resources/config/routing_incidencia.yml

incidencia:
    type:     rest
    resource: Gitek\RegistroBundle\Controller\IncidenciaController
    name_prefix:  api_

最后,这是我在#app/config.yml 上对 fos_rest 的配置:

fos_rest:
    routing_loader:
        default_format: null
    view:
        default_engine: twig
        force_redirects:
            html: true
        formats:
            json: true
            xml: true
        templating_formats:
            html: true
        view_response_listener: 'force'
        failed_validation: HTTP_BAD_REQUEST
    exception:
        codes: ~
        messages: ~
    body_listener:
        decoders:
            json: fos_rest.decoder.json
            xml: fos_rest.decoder.xml
    format_listener:
        default_priorities: [json, html, '*/*']
        fallback_format: html
        prefer_extension: true
    service:
        router: router
        templating: templating
        serializer: serializer
        view_handler: fos_rest.view_handler.default  

任何帮助或线索?

4

1 回答 1

2

你的控制器类应该被命名IncidenciaController而不是UsuarioController

于 2012-06-21T17:26:12.590 回答