我使用以下步骤安装了Symfony4。
step1: composer create-project“Symfony/ step4:^4.0”symfony4 step2: git status step3: git add。step4: git commit step5: composer require 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));
}
}Step7:访问http://127.0.0.1:8000你可以看到‘天哪!我的第一个页面已经!哇哦!’。
但是http://127.0.0.1:8000/123和http://127.0.0.1:8000/news/test不能工作。谁能告诉我为什么?请帮我解决这个问题。
发布于 2018-02-06 15:58:19
只要找到解决方案就行。
composer需要symfony/apache-pack
它将自动生成.htaccess。
发布于 2019-04-12 03:49:58
正确的命名空间是:
use Symfony\Component\Routing\Annotation\Route;
谢谢
https://stackoverflow.com/questions/48637963
复制相似问题