2017-09-15 7 views
0

私はsymfonyのopenclassroomsチュートリアルに従っています。私は現在、 "Les controleurs avec Symfony"の章にいます。Symfony Component Routing Exception InvalidParameterException

私はhttp://localhost/Symfony/web/app_dev.php/platformを開こうと、私はここでは、このエラーに

InvalidParameterException

を取得するには、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."." 
     ); 
     } 
} 
?> 

私はエラーが何を意味するのか理解していないとわかりませんそれを修正する方法。 ありがとうございます!これは、それを修正する必要がありますD + を\する

+0

routing.ymlから 'neo_platform_view'のルート定義を表示できますか? – Joe

+0

neo_platform_view: パス:/広告/ {ID} デフォルト: _controller:NeoPlatformBundle:広告:ビュー 要件: ID:\のID + –

+0

あなたはおそらく別のを開始する前に、一つの質問を終える必要があります。チュートリアルでこのような問題が発生している場合は、別のものを試してみてください。ドキュメントのように?ルート定義のようなものを追加するときに質問を更新してください。コメントはうまくフォーマットされません。 – Cerad

答えて

0
neo_platform_view: 
    path: /advert/{id} 
    defaults: 
     _controller: NeoPlatformBundle:Advert:view 
    requirements: 
     id: \d+ 

変更\ IDが+。 \ d +だけ数字を許可したい場合は、正しい条件です。

https://symfony.com/doc/current/routing/requirements.htmlさらに要件については、

+0

ジョー、awsome!それだった!どうもありがとうございました! –

関連する問題