drd94483 2016-07-11 15:50
浏览 221
已采纳

为什么localhost:8000不起作用,而...:8000 / test在symfony上正常工作?

Im completely new to Symfony so please bear with me. Im trying to configure my controller to atleast get a working webpage. I created a new Symfony project and started my server. After writing some code into MyController

<?php

namespace AppBundle\Controller;

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

 class MyController
{
 /**
 * @Route("/test")
 */
 public function numberAction()
 {
    $prankBro= "Its just a prank bro";

    return new Response($prankBro);
 }
}

After trying to access localhost:8000 I get a fatal 404 error: No route found for "GET /" Being a complete beginner I have no idea what this is. I believe it is some kind of response type, although I'm not sure. On the other hand if I use localhost:8000/test It seems to be working fine, I get my webpage with a message saying that it was just a prank bro :) Is this how it is supposed to be in symfony? It really messes up with my brain, so if it is fine, can someone explain me why plain localhost:8000 URL gives me 404 error? Thank you!

  • 写回答

1条回答 默认 最新

  • doupin5408 2016-07-11 15:54
    关注

    Take note of the comment above numberAction:

    /**
    * @Route("/test")
    */
    

    That implies to me that there is a route set up for localhost:8000/test which will execute the numberAction method.

    You need to create a method that will be your home page, and then create a route for / which will run your new method. Then when you visit localhost:8000, your new method will be executed.

    See the Symphony documentation for details on how to set up routes.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?