我使用以下步骤安装了Symfony4。
step1:composer create-project" Symfony / skeleton:^ 4.0“symfony4 step2:git状态 step3:git add。 step4:git commit step5:作曲家需要注释 step6:创建一个名为ArticleController的控制器
<?php
namespace App\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\HttpFoundation\Response;
class ArticleController
{
/**
* @Route("/")
*/
public function indexAction()
{
return new Response('OMG! My first page already! Wooooo!');
}
/**
* @Route("/{id}", requirements={"id" = "\d+"}, defaults={"id" = 1})
*/
public function showAction($id)
{
echo 123;die;
}
/**
* @Route("/news/{$slug}")
* @Method({"GET", "POST"})
*/
public function news($slug)
{
return new Response(sprintf('Today new is "%s"', $slug));
}
}
第7步:访问http://127.0.0.1:8000 你可以查看&#39; OMG!我的第一页已经! WOOOOO&#39;!
但http://127.0.0.1:8000/123和http://127.0.0.1:8000/news/test不起作用。谁能告诉我为什么?请帮我解决。
答案 0 :(得分:0)
找到解决方案。
composer需要symfony / apache-pack
它会自动生成.htaccess。
答案 1 :(得分:0)
正确的名称空间是:
use Symfony\Component\Routing\Annotation\Route;
谢谢