简体   繁体   English

Symfony第一步问题

[英]Symfony first-steps problems

I'm newbie in Symfony and I'm following a tutorial. 我是Symfony的新手,我正在学习教程。 The first excercise is very simple, but I don't know why is not working. 第一次练习很简单,但我不知道为什么不工作。

In my source folder I first tried with these lines: 在我的源文件夹中,我首先尝试使用以下行:

<?php

namespace AppBundle\Controller;


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

class GenusController
{
    /**
     * @Route("/genus")
     */

    public function showAction()
    {
        return new Response('Test ');

    }

}

I tried in in my browser: 我在浏览器中尝试过:

http://localhost:8888/my_project/web/genus

And it works. 它有效。 But then if I add new lines: 但是如果我添加新行:

class GenusController
{
    /**
     * @Route("/genus/{genusName}")
     */

    public function showAction($genusName)
    {
        return new Response('The genus: '.$genusName);

    }

}

and tested it: 并测试了它:

http://localhost:8888/my_project/web/genus/test

My browser displays: 我的浏览器显示:

Oops! 哎呀! An Error Occurred The server returned a "404 Not Found". 发生错误服务器返回“404 Not Found”。 Something is broken. 有些东西坏了。 Please let us know what you were doing when this error occurred. 发生此错误时,请告诉我们您在做什么。 We will fix it as soon as possible. 我们会尽快修复它。 Sorry for any inconvenience caused. 给您造成的任何不便,请原谅。

What is missing? 什么东西少了? Any suggestions? 有什么建议么?

Thank you in advance 先感谢您

In prod environment: the configuration information is cached and not automatically refreshed. prod环境中: 配置信息被缓存,不会自动刷新。 It means: 它的意思是:

  • @nnotation in php files are cached 缓存php文件中的@nnotation
  • .yml file are cached .yml文件被缓存
  • .xml file are cached .xml文件被缓存
  • *.twig file are cached * .twig文件被缓存

The error you are having is the new route you've created is not cached and not accessible to prod environment. 您遇到的错误是您创建的新路由未缓存且无法访问prod环境。

It means you either have to call app/console cache:clear --env=prod everytime or you have to use the dev environnement which is far better when developping. 这意味着您要么必须调用app/console cache:clear --env=prod每次app/console cache:clear --env=prod或者您必须使用dev时更好的开发环境。 It provides better error message for 404 and 500 errors too. 它还为404和500错误提供了更好的错误消息。

It means you have to use the app_dev.php instead of app.php . 这意味着您必须使用app_dev.php而不是app.php You can try 你可以试试

http://localhost:8888/app_dev.php/my_project/web/genus/test

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM