【发布时间】:2018-02-05 11:44:11
【问题描述】:
我正在尝试通过 localhost (Xampp) 访问 Symfony 项目中文件夹中的索引文件。尽管我正在编写以下路径,但它找不到该页面:http://localhost/google_analytics_app/consolytics-app/analytics/ tree-folder-structure
按照说明,我在 viwes/analytics/ 文件夹下的 index.html.twig 文件中使用基本文件
{% extends 'base.html.twig' %}
并在文件夹/analytics/index.html.twig 下使用我自己的索引文件。 我还在 src/AppBundle/Controller/IndexController.php 中使用了注释:
<?php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use AppBundle\Library\GoogleAnalytics;
use Doctrine\Common\Util\Debug as dump;
class IndexController extends Controller
{
/**
* @Route("/analytics/index", name="homepage")
*/
public function indexAction(Request $request)
{
....
return $this->render('index.html.twig');
}
}
输入路径时会显示 404 错误消息。有人可以帮助解决这个路由问题吗?在我的 composer.json 文件中:
"require": {
"twig/twig": "^1.0||^2.0"
},
【问题讨论】:
-
你没有忘记在 routing.yml 文件中注册路由吗?
-
如果你声明你的路由为
/analytics/index,你应该调用相同的url(你忘了/index部分)http://localhost/google_analytics_app/consolytics-app/analytics/index -
@zalex 但这就是注释的作用?我的意思是你不必注册到路由文件,只在控制器中..但是在尝试了 routing.yml 文件之后我仍然有同样的问题:
index: resource: app/Resources/views/analytics/index.html prefix: /analytics/index@goto 我也试过了,但仍然是一样的。