dongmubi4444 2018-06-29 20:15
浏览 71

无法访问我的Symfony控制器@Route

I'm new with Symfony (using version 3.4). And I'm using it with XAMPP on macOS High Sierra. I set my vhosts like this:

<VirtualHost *:80>
   DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/project/web/app_dev.php"
   ServerName project
</VirtualHost>

And set my hosts file with "127.0.0.1 project" and that works fine.

But then in my application I created a Controller:

<?php

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

class ProjectController extends Controller
{ 
    /**
    * @Route("/todo", name="todo_list")
    */
    public function indexAction(Request $request)
    {
        die("TO DOS");
        // replace this example code with whatever you need
        return $this->render('default/index.html.twig', [
            'base_dir' => realpath($this- 
            >getParameter('kernel.project_dir')).DIRECTORY_SEPARATOR,
         ]);
    }
}

but when I access to project/todo it redirects to project/dashboard and shows XAMPP welcome page. How can I go to project/todo ?

NOTE: Although I'm using Mac I'm doing this tutorial https://www.youtube.com/watch?v=HchMW8EhWPU

  • 写回答

2条回答 默认 最新

  • duanlv5084 2018-06-29 22:06
    关注

    I had limited experience with Apache + Symfony, but I believe your DocumentRoot is incorrent. You should point to web directory instead of your prod or dev front controller. For the testing purposes, just remove the app_dev.php from the very end. Did that help?

    Based on your version, always consult official docs, like this one: Configuring a Web Server

    In order to debug your routes, I suggest your run bin/console debug:router in order to gather better insight in you registered routes.

    Hope this helps a bit...

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用