我正在关注symfony的openclassrooms教程。我现在正处于" Les controleurs avec Symfony"。
我尝试打开http://localhost/Symfony/web/app_dev.php/platform并收到此错误
这是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 :(得分:0)
neo_platform_view:
path: /advert/{id}
defaults:
_controller: NeoPlatformBundle:Advert:view
requirements:
id: \d+
将\ id +更改为\ d + 这应该解决它。如果你只想允许数字\ d +是正确的条件。
https://symfony.com/doc/current/routing/requirements.html有关要求的进一步阅读。