【问题标题】:Symfony\Component\HttpKernel\Exception\ NotFoundHttpExceptionSymfony\Component\HttpKernel\Exception\ NotFoundHttpException
【发布时间】:2017-09-15 20:56:10
【问题描述】:

我正在关注 symfony 上的 openclassrooms 教程。我现在在“Les controleurs avec Symfony”一章。

我尝试打开 http://localhost/Symfony/web/app_dev.php 并收到此错误

NotFoundHttpException

我怀疑错误来自 AdvertController.php。 但是我将它与教程中给定的代码进行了比较。它是完全一样的。然后我尝试删除缓存,但它不起作用。我将为此提出另一个问题。

这里是 AdvertController.php 代码:

<?php
//src/Neo/PlatformBundle/Controller/AdvertController.php
namespace Neo\PlatformBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
//use Symfony\Component\Routing\Generator\UrlGeneratorInterface;


class AdvertController extends Controller
{
    public function indexAction()
    {
      $url= $this->get('router')->generate(
    'neo_platform_view', //first argument : path name
    array('id' => 5)
  );
    return new Response("The url of the announcement is:".$url);
}

public function viewAction($id)
{
  return new Response("Desplay of the announcment with id:".$id);
}

public function viewSlugAction($slug, $year, $_format)

  {

      return new Response(

          "We could desplay the announcment conrresponding the the slug          
'".$slug."', created in ".$year." and with the format ".$_format."."

          );

      }


}



?>

如果您希望我发布其他代码部分,请告诉我。 我不知道在哪里看。

非常感谢!

【问题讨论】:

    标签: symfony


    【解决方案1】:

    您可以尝试使用命令php bin/console debug:routerapp/console for symfony

    您的根路径需要一个默认路由。

    【讨论】:

    • 你好勒米努!我尝试了您提到的命令,但收到此消息:无法打开输入文件:bin/console 同样在 app/config/routing.yml 我有一个默认路由定义为前缀:/platform。实际上,我可以在这里解决我的问题stackoverflow.com/questions/46240068/…,但我对 debug:router 很好奇。知道如何让它在我的控制台上运行吗?谢谢
    • 您需要位于应用程序的根路径。如果你有 symfony v2.X,你必须使用 app/console 而不是 bin/console (就像任何其他控制台命令一样启动它)
    • 谢谢Lerminou。实际上我不知道如何将自己置于根路径。当我想打开我的 Symfony 文件夹时,我总是需要在控制台上写 gksudo nautilus /opt/lammp/htdocs 以使它们可见。执行此操作后,终端窗口不接受其他命令。我需要打开另一个终端窗口来进行其他操作。我会在另一篇文章中单独提出这个问题。
    【解决方案2】:

    消息错误非常明确,“/”没有路由。尝试验证您的 routing.yml

    【讨论】:

    • 您好!感谢您的评论。我实际上检查了 app/config/routing.yml:里面我写了:前缀:/平台因此认为 Rersources/config/routing.yml 只需要路径:/{page} 而不是路径:/{page} .我做的和教程中的完全一样。我该如何解决这个问题?非常感谢!
    猜你喜欢
    • 2021-05-28
    • 2014-06-28
    • 2021-12-19
    • 2021-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多