Symfony 3 简单路线不起作用 [英] Symfony 3 simple route dosn't work

查看:27
本文介绍了Symfony 3 简单路线不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个绝对清晰的标准 Symfony 安装,这是主页 http://triod.ru/project/web/(我只是将 prod 更改为 dev 以便我可以看到日志)

I have an absolutely clear standart Symfony installation, here's the homepage http://triod.ru/project/web/ (I only changed prod to dev so I could see the logs)

我在 src/AppBundle/Controller 目录下创建了一个 LuckyController.php 文件

I made a file LuckyController.php in src/AppBundle/Controller directory

<?
// src/AppBundle/Controller/LuckyController.php
namespace AppBundle\Controller;

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

class LuckyController
{
    /**
     * @Route("/lucky/number")
     */
    public function numberAction()
    {
        $number = rand(0, 100);

        return new Response(
            '<html><body>Lucky number: '.$number.'</body></html>'
        );
    }
}

但是页面上没有任何内容http://triod.ru/project/web/lucky/号码该类本身取自 Symfony 官方教程/文档,但它不起作用.我不知道这怎么可能.

but there's nothing on the page http://triod.ru/project/web/lucky/number The class itself was taken from the Symfony official tutorial/documentation, but it doesn't work. I have no idea how it is possible.

推荐答案

如上所述,扩展基类 Controller 对我不起作用.为了解决这个问题,我必须在 web/app.php 中做以下更改

As mentioned above, extending the base class Controller did not work for me. To solve the problem I had to do the following change in web/app.php

$kernel = new AppKernel('prod', true);

我还必须在网址中添加en":http://scotchbox.demo/en/lucky/number

Also I had to add 'en' in the url: http://scotchbox.demo/en/lucky/number

这篇关于Symfony 3 简单路线不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆