【发布时间】:2018-01-18 20:35:16
【问题描述】:
我已经在 C9.IO 上安装并设置了 Symfony 3.3.6。
但是,我在添加自定义控制器和视图时遇到了问题。我已按照所有说明进行操作,但在尝试访问页面/路由时出现 404 错误。这是我通过以下方式访问此页面的网址:https://symfony4-XXXX.c9users.io/test
我在目录src/Controller/TestController.php 中添加了一个名为TestController.php 的控制器。
在这个控制器中,我有以下代码:
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
class TestController extends Controller
{
/**
* @Route("/", name="test")
*/
public function testAction(Request $request)
{
// replace this example code with whatever you need
return $this->render('test/test.html.twig', [
'base_dir' => realpath($this->getParameter('kernel.project_dir')).DIRECTORY_SEPARATOR,
]);
}
}
我已将视图“test.html.twig”添加到目录“app/Resources/views/test/test.html.twig”中
这个文件中的代码是:
{% extends 'base.html.twig' %}
{% block body %}
<p>This is my test page.</p>
{% endblock %}
我的 routing.yml 文件设置为:
app:
resource: '@AppBundle/Controller/'
type: annotation
为什么我无法访问此页面?我不断收到404 错误。
日志只显示:
[2017-08-10 13:00:13] request.ERROR: 未捕获的 PHP 异常 Symfony\Component\HttpKernel\Exception\NotFoundHttpException:“否 找到“GET /test”的路线 /home/ubuntu/workspace/var/cache/prod/classes.php 第 4173 行 {“异常”:“[对象] (Symfony\Component\HttpKernel\Exception\NotFoundHttpException(代码: 0): 没有找到 \"GET /test\" 的路由 /home/ubuntu/workspace/var/cache/prod/classes.php:4173, Symfony\Component\Routing\Exception\ResourceNotFoundException(代码: 0): 在 /home/ubuntu/workspace/var/cache/prod/appProdProjectContainerUrlMatcher.php:47)"} []
【问题讨论】:
-
您是否查看了日志以了解更多详细信息?
-
是的,请参阅更新/编辑。