Symfony 6中的路由注释不起作用
我正在Homestead上运行Symfony应用程序,但是当通过注释添加路由以进行简单操作时,它行不通。
namespace App\Controller;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class BlogController extends AbstractController
{
/**
* @Route("/index",name="blog_index")
*/
public function index(){
dd('Test KO');
}
}
用于路线调试器
vagrant@homestead:~/code/symfony61$ php bin/console debug:router
-------------------------- -------- -------- ------ -----------------------------------
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_xdebug ANY ANY ANY /_profiler/xdebug
_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
-------------------------- -------- -------- ------ -----------------------------------
i'm running a symfony application on Homestead, but when adding a route by annotation for simple action it doesn't work.
namespace App\Controller;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class BlogController extends AbstractController
{
/**
* @Route("/index",name="blog_index")
*/
public function index(){
dd('Test KO');
}
}
for routes debugger
vagrant@homestead:~/code/symfony61$ php bin/console debug:router
-------------------------- -------- -------- ------ -----------------------------------
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_xdebug ANY ANY ANY /_profiler/xdebug
_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
-------------------------- -------- -------- ------ -----------------------------------
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Symfony 6不会带有预先配置的路由注释config。因此,您需要按照以下简单的步骤操作:
1-在config/routes文件夹下创建一个属性.yaml文件。
2-添加以下代码
3-使用新语法添加您的路由注释,例如
4-如果一切正常,请调试路线
Symfony 6 is not coming with preconfigured route annotation config. So you need to follow this easy steps:
1- create a attributes.yaml file under config/routes folder.
2- add following code
3- add your route annotation with new syntax like
4- Debug your route if everything is ok
通常有一个文件:config/doutes.yaml,带有内容:
请参阅: https://symfony.com/doc/current/routing.html#creating-routes-routes-as-attributes-or-antributes-or-annotations
There is usually a file: config/routes.yaml with the content:
See: https://symfony.com/doc/current/routing.html#creating-routes-as-attributes-or-annotations
php8 + Symfony 6使用PHP注释:#[route('/',name:'app_index')]
PHP8 + Symfony 6 use PHP annotations: #[Route('/', name: 'app_index')]
在Symfony 6和PHP 8中,您可以使用PHP属性而不是Symfony注释。这样使用。
In symfony 6 and PHP 8, You can use PHP attributes instead of symfony annotation. Use like this.