以下是详细信息:
的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
答案 0 :(得分:1)
无需将此配置复制到routing.yml和routing_dev.yml
这一行:resource: "@TemplateManagerDocumentGeneratorBundle/Controller/API"
应该是正确的。从routing.yml
删除注释行,并从app_api
删除routing_dev.yml
条目。
如果仍然不正确,请在...Bundle.php
目录中发布src/TemplateManager/Bundle/DocumentGeneratorBundle/
文件的内容。