2017-09-15 453 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以使它們可見。完成後,終端窗口不接受其他命令。我需要打開另一個終端窗口進行其他操作。我會在另一篇文章中單獨提出這個問題。 –

相關問題