我'm trying to access through localhost (Xampp) the index file from the folder in a Symfony project. Although i'我写了以下路径找不到页面:http://localhost/google_analytics_app/consolytics-app/analytics/ tree-folder-structure
按照说明我在index.html.twig文件中的文件viwes / analytics /下使用基本文件
{% 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"
},
2 回答
问题是你没有在routing.yml文件中注册你的路由 .
您必须了解注释是描述路由,但是在您在routing.yml文件中注册该路由之前,您的路由器组件现在没有任何关于您的路由的信息 . 从此文件(v3.4)路由器获取您的路由 .
https://symfony.com/doc/3.4/best_practices/controllers.html#routing-configuration
支付类型参数的附件 . 注释告诉路由器您的路由实际上是注释:)
你的渲染方法的参数是错误的 . 它必须返回
$this->render('views/analytics/index.html.twig');