暫時學習Symfony。甚至無法啓動,因爲註釋路由在我的項目中不起作用。無法在Symfony 3中設置註釋路由
我需要在我的項目中使用控制器中的註釋路由所有項目asoft/OrganizerBundle。
我所做的:
E:\ Program Files文件\ Apache24 \ htdocs中\ symfony.local \組織者\程序\ CONFIG \ routing.yml中
organizer:
resource: "@OrganizerBundle/Resources/config/routing.yml"
type: annotation
app:
resource: '@AppBundle/Controller/'
E:\ Program Files文件\ Apache24 \ htdocs目錄\ symfony.local \主辦的\ src \輕聲\ OrganizerBundle \資源\ CONFIG \的routing.yml:
organizer:
resource: "@OrganizerBundle/Controller/"
type: annotation
\ Program Files文件\ Apache24 \ htdocs中\ symfony.local \主辦的\ src \輕聲\ OrganizerBundle \控制器\ DefaultController.php:
<?php
declare(strict_types = 1);
namespace asoft\OrganizerBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class DefaultController extends Controller
{
/**
* @Route("/")
*/
public function showMainAction(): Response
{
return $this->showDayAction((new \DateTime())->format('Y-m-d'));
}
/**
* @Route("/{day}")
*/
public function showDayAction(string $day): Response
{
echo $day;
return $this->render('OrganizerBundle:Default:index.html.twig');
}
}
當我訪問URL /,我看到錯誤500,這在日誌:
request.CRITICAL: Uncaught PHP Exception InvalidArgumentException: "The controller for URI "/" is not callable. Expected method "indexAction" on class "asoft\OrganizerBundle\Controller\DefaultController". Available methods: "showMainAction", "showDayAction", "setContainer"." at E:\Program Files\Apache24\htdocs\symfony.local\organizer\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Controller\ControllerResolver.php line 98 {"exception":"[object] (InvalidArgumentException(code: 0): The controller for URI \"/\" is not callable. Expected method \"indexAction\" on class \"asoft\OrganizerBundle\Controller\DefaultController\". Available methods: \"showMainAction\", \"showDayAction\", \"setContainer\". at E:\Program Files\Apache24\htdocs\symfony.local\organizer\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Controller\ControllerResolver.php:98)"} []
當我訪問/ 2007-05-02,我收到錯誤404,這:
request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET /2007-05-02"" at E:\Program Files\Apache24\htdocs\symfony.local\organizer\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\EventListener\RouterListener.php line 125 {"exception":"[object] (Symfony\Component\HttpKernel\Exception\NotFoundHttpException(code: 0): No route found for \"GET /2007-05-02\" at E:\Program Files\Apache24\htdocs\symfony.local\organizer\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\EventListener\RouterListener.php:125, Symfony\Component\Routing\Exception\ResourceNotFoundException(code: 0): at E:\Program Files\Apache24\htdocs\symfony.local\organizer\var\cache\prod\appProdProjectContainerUrlMatcher.php:56)"} []
怎麼了?我需要在我的yml文件中指定什麼?
'organizer:resource:「@ OrganizerBundle/Resources/config/routing.yml」type:annotation' - 從本節中刪除'type:annotation'。它不是註釋類型。 –
清除完成+緩存。沒有改變。 – Audiophile