Symfony 2:加载URI时未找到资源错误 - 404错误

时间:2016-09-26 19:10:20

标签: php symfony routing

以下是详细信息:

文件结构 enter image description here

的routing.yml

app_api:
#     resource: "@TemplateManager/Bundle/DocumentGeneratorBundle/Controller/API"
     resource: "@TemplateManagerDocumentGeneratorBundle/Controller/API"
     type:     annotation

routing_dev.yml

app_api:
     resource: "@TemplateManager/Bundle/DocumentGeneratorBundle/Controller/API"
#     resource: "@TemplateManagerDocumentGeneratorBundle/Controller/API"
     type:     annotation

App Kernel

$bundles = array(
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Symfony\Bundle\AsseticBundle\AsseticBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new TemplateManager\Bundle\DocumentGeneratorBundle\TemplateManagerDocumentGeneratorBundle(),
            new FOS\UserBundle\FOSUserBundle(),
        );

控制器

<?php
namespace TemplateManager\Bundle\DocumentGeneratorBundle\Controller\API;

use Symfony\Component\HttpFoundation\Response;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;



class ClientController
{
    /**
     * @Route("api/clients")
     * @Method("GET")
     */

    public function allAction()
    {
        return new Response("Lets Do this");
    }
}

DocumentGeneratorBundle

namespace TemplateManager\Bundle\DocumentGeneratorBundle;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use TemplateManager\Bundle\DocumentGeneratorBundle\DependencyInjection\Compiler\OverrideServiceCompilerPass;

class TemplateManagerDocumentGeneratorBundle extends Bundle
{
}

路由的应用控制台错误

 php app/console router:debug
[Symfony\Component\Config\Exception\FileLoaderLoadException]                                                                                                                      
  Cannot load resource "@TemplateManager/Bundle/DocumentGeneratorBundle/Controller/API". Make sure the "TemplateManager" bundle is correctly registered and loaded in the applicat  
  ion kernel class. 

访问URI时出错

  

TwigBundle:异常:error404.html.twig

1 个答案:

答案 0 :(得分:1)

无需将此配置复制到routing.yml和routing_dev.yml

这一行:resource: "@TemplateManagerDocumentGeneratorBundle/Controller/API"应该是正确的。从routing.yml删除注释行,并从app_api删除routing_dev.yml条目。

如果仍然不正确,请在...Bundle.php目录中发布src/TemplateManager/Bundle/DocumentGeneratorBundle/文件的内容。