我在Symfony中的路由有问题。我把它们作为注释。我用创建了控制器
php bin/console make: controller DefaultController
Symfony的localhost/.../public/index.php
页面显示了控制器,但如果我放localhost/.../public/index.php/welcome
,它不会显示任何内容,我找不到错误
php bin/console debug:route
-------------------------- -------- -------- ------ -----------------------------------
Name Method Scheme Host Path
-------------------------- -------- -------- ------ -----------------------------------
_preview_error ANY ANY ANY /_error/{code}.{_format}
_wdt ANY ANY ANY /_wdt/{token}
_profiler_home ANY ANY ANY /_profiler/
_profiler_search ANY ANY ANY /_profiler/search
_profiler_search_bar ANY ANY ANY /_profiler/search_bar
_profiler_phpinfo ANY ANY ANY /_profiler/phpinfo
_profiler_search_results ANY ANY ANY /_profiler/{token}/search/results
_profiler_open_file ANY ANY ANY /_profiler/open
_profiler ANY ANY ANY /_profiler/{token}
_profiler_router ANY ANY ANY /_profiler/{token}/router
_profiler_exception ANY ANY ANY /_profiler/{token}/exception
_profiler_exception_css ANY ANY ANY /_profiler/{token}/exception.css
autor ANY ANY ANY /autor
autor_list ANY ANY ANY /autor/list
autor_list_JSON ANY ANY ANY /autor/listJSON
autor_new ANY ANY ANY /autor/new
home ANY ANY ANY /welcome
/autor、/autor/list、autor/listJSON、autor/new路径也不起作用。
我的路线。yaml
#index:
# path: /
# controller: AppControllerDefaultController::index
我的控制器
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentRoutingAnnotationRoute;
use SymfonyComponentHttpFoundationRequest;
class DefaultController extends AbstractController
{
/**
* @Route("/default", name="default")
*/
public function index(): Response
{
return $this->render('default/index.html.twig', [
'controller_name' => 'DefaultController',
]);
}
/**
* @Route("/welcome", name="home")
*/
public function welcome()
{
$html = '<body>Hello world!</body>';
return new Response($html);
}
}
删除供应商文件夹并使用再次生成
composer install --ignore-platform-reqs
现在它工作正常。供应商内部有一个不正确的实例。
重要,使用--ignore-platform-reqs
生成