2017-09-15 451 views
1

我正在关注symfony上的openclassrooms教程。我现在正在阅读“Symfony的控制者”一章。Symfony Component HttpKernel Exception NotFoundHttpException

我尝试打开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."." 

     ); 

     } 


} 



?> 

如果你想我张贴的代码其他地方,请让我知道。 我不知道,在哪里看。

非常感谢!

回答

0

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

+0

您好!感谢您的评论。我实际上检查了app/config/routing.yml:我写了:prefix:/ platform因为这个原因,认为Rersources/config/routing.yml只包含路径:/ {page}而不是路径:/ {page} 。我在教程中完全一样。我怎么能解决这个问题?非常感谢! –

0

您可以尝试使用命令php bin/console debug:routerapp/console为symfony < 3.0转储您的路由,以查看是否存在您所需路径的路由。 如果您有前缀/平台,您的控制器内的路径现在是/ platform/path而不是/ path。

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

+0

Hello Lerminou!我尝试了你提到的命令,但是我收到了以下消息:无法打开输入文件:bin/console 同样在app/config/routing.yml中,我有一个默认路由被定义为前缀:/ platform。其实,我可以解决我的问题在这里https://stackoverflow.com/questions/46240068/symfony-component-routing-exception-invalidparameterexception但我很好奇的调试:路由器。任何想法如何使它在我的控制台上工作?谢谢 –

+0

您需要位于应用程序的根路径。如果您有symfony v2.X,则必须使用'app/console'而不是'bin/console'(与其他任何控制台命令一样启动) – Lerminou

+0

谢谢Lerminou。其实我不知道如何把我的自我放在根本的道路上。当我想打开我的Symfony文件夹时,我总是需要在控制台上编写gksudo nautilus/opt/lammp/htdocs以使它们可见。完成后,终端窗口不接受其他命令。我需要打开另一个终端窗口进行其他操作。我会在另一篇文章中单独提出这个问题。 –

相关问题