【发布时间】:2014-07-14 20:40:02
【问题描述】:
我正在尝试在Symfony 中创建我的第一个捆绑包。本教程将引导您完成创建名为“Acme”的包的过程。因为我下载了 symfony 2.4,它与 Acme Demo 捆绑包一起提供。我将所有“AcmeBundle”更改为“myAcmeBundle”。我创建了控制器、路由和包,与指令完全一样,只是包的名称除外。
tut 说如果我去
http://localhost/app_dev.php/hello/Ryan
它应该调用我的 HelloController.php 我的问题是 symfony 如何知道我要运行哪个包。我的“src”文件夹中现在有 2 个捆绑包。每当我输入 localhost/app_dev.php/hello/Ryan 时,它都会在 AcmeBundle (默认演示包)中显示 HelloController.php 的内容。我想在 myAcmeBundle(我新创建的包)中显示 HelloController.php 的内容。
附加信息: 可能与 AppKernel 类有关,但不太确定
class AppKernel extends Kernel
{
public function registerBundles()
{
$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 myAcme\HelloBundle\myAcmeHelloBundle(),
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Acme\DemoBundle\AcmeDemoBundle();
//$bundles[] = new myAcme\HelloBundle\myAcmeHelloBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
return $bundles;
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
}
}
app\config\routing.yml
my_acme_hello:
resource: "@myAcmeHelloBundle/Resources/config/routing.yml"
prefix: /
src\myAcme\HelloBundle\Resources\config\routing.yml
my_acme_hello_homepage:
path: /hello/{name}
defaults: { _controller: myAcmeHelloBundle:Default:index }
【问题讨论】:
-
您需要调整路由设置。你读过this 页面吗?
-
您是否删除了
src/Acme/HelloBundle/Resources/config/routing.yml的路由条目?首先找到的匹配项将用于选择控制器。
标签: php symfony routing bundle