我一直在关注 symfony 的教程,但遇到了障碍。
我的设置是 xampp 的当前版本(在 Windows 上运行),所以我的 apache 和 php 是相对最新的。
在这里跟随他们的“快速游览”:
http://symfony.com/doc/current/quick_tour/the_big_picture.html
在开发环境中一切都很好。但是,进一步遵循指南,我开始通过此处的指南创建自己的测试包:
http://symfony.com/doc/current/book/page_creation.html
并且无法让它在生产环境中正常工作。 (它在开发环境中运行良好,就像预装的演示一样。
我曾尝试通过 php app/console cache:clear --env=prod --no-debug 命令清除缓存,但这并没有帮助(而且似乎也是搜索时弹出的唯一建议。
查看路线时,我可以看到我的“/hello/{name}”路线在路线列表中显示良好。
我的 app/config/routing.yml 有:
acme_hello:
resource: "@AcmeHelloBundle/Resources/config/routing.yml"
prefix: /
正如它应该的那样,然后我的 src/Acme/HelloBundle/Resources/config/routing.yml 有
hello:
path: /hello/{name}
defaults: { _controller: AcmeHelloBundle:Hello:index }
有没有人对可能出现的问题有任何建议? (我还尝试通过从 routing_dev.yml 文件中复制路由信息并在 appkernel.php 文件中重新分配包来将开箱即用的演示转换为生产路由,但这有同样的问题)
- -编辑 - -
每个请求,这是我的 appkernel.php 文件
使用 Symfony\Component\HttpKernel\Kernel;
使用 Symfony\Component\Config\Loader\LoaderInterface;
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 JMS\AopBundle\JMSAopBundle(),
new JMS\DiExtraBundle\JMSDiExtraBundle($this),
new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
new Acme\HelloBundle\AcmeHelloBundle(),
new Acme\DemoBundle\AcmeDemoBundle(),
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$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');
}
}
---第二次编辑---
我发现了问题。我觉得很奇怪,prod 日志中没有显示任何内容,所以我想可能是有什么东西在重定向我,导致我完全错过了 app.php 文件。
事实证明,这就是问题所在。我清空了 web 文件夹中的 .htaccess 文件的内容(symfony 预先配置的那个),然后一切都神奇地开始工作。
最佳答案
我也有同样的问题。我分享我是如何解决它的(奇怪但它有效)。
在文件 web/app.php 中更改:
$kernel = new AppKernel('prod', false);
经过
$kernel = new AppKernel('prod', true); // Enable debug mode
然后在浏览器中加载页面(在应用程序环境中)并再次更改文件以禁用调试:
$kernel = new AppKernel('prod', false);
再次尝试在浏览器中加载页面。它应该可以正常工作。
此致,
关于symfony - 从 symfony 2 开始(app_dev.php 有效,app.php 404),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16243746/