【问题标题】:Cannot import resource error无法导入资源错误
【发布时间】:2012-06-21 16:55:00
【问题描述】:

我刚刚安装了 FOSRestBundle 我在运行 cache:clear 时遇到了这个错误

[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  

任何帮助或线索??

【问题讨论】:

    标签: php symfony


    【解决方案1】:

    您的控制器类应命名为IncidenciaController 而不是UsuarioController

    【讨论】:

    • 尤尔!!谢谢!!!我快疯了!!你知道..复制和粘贴...非常感谢!
    猜你喜欢
    • 2013-03-14
    • 1970-01-01
    • 1970-01-01
    • 2013-01-10
    • 1970-01-01
    • 2015-09-09
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    相关资源
    最近更新 更多