我有一个需要获取类别和子类别的路由,路由的形式如下:
#[Route('/{slug}/{subSlug}', name: 'subcategory')]
#[Entity('category', expr: 'repository.findOneBySlug(slug)')]
#[Entity('subcategory', expr: 'repository.findOneBySlug(subSlug)')]
public function subcat(Category $cat, Subcategory $sub): Response
我尝试访问 /mtg/dmr,但是我得到了一个404的对象未找到错误,由@ParamConverter引起。
当我在Doctrine日志中查看时,系统在正确的表中查找,但是对于两个都在寻找mtg而不是先找mtg然后找dmr。有什么想法是怎么回事吗?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
DOC示例:
#[Route('/blog/{date}/{slug}/comments/{comment_slug}')] #[ParamConverter('post', options: ['mapping' => ['date' => 'date', 'slug' => 'slug']])] #[ParamConverter('comment', options: ['mapping' => ['comment_slug' => 'slug']])] public function showComment(Post $post, Comment $comment) { }所以,在您的情况下,您必须有:
#[Route('/{slug}/{subSlug}', name: 'subcategory')] #[ParamConverter('cat', options: ['mapping' => ['slug' => 'slug']])] #[ParamConverter('sub', options: ['mapping' => ['subSlug' => 'slug']])] public function (Category $cat, Subcategory $sub): Response { }