必须定义参数 "id"

The parameter "id" must be defined

当我尝试访问我的子页面时,弹出此错误

The parameter "id" must be defined.

> Symfony\Component\DependencyInjection\Exception\
InvalidArgumentException
in var/cache/dev/Container6do1xtb/appDevDebugProjectContainer.php (line 4787)
appDevDebugProjectContainer->getParameter('id')
in vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php (line 40)
Controller->getParameter('id')
in src/AppBundle/Controller/DefaultController.php (line 22)
//        $paginator->setItemCountPerPage(10);//        $this->view->paginator  = $paginator;    }    public function blogarticleAction(){        $this->view->blogarticle = \Pimcore\Model\DataObject\Blogpost::getById($this->getParameter("id"));    }}
DefaultController->blogarticleAction()
in vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php (line 151)
HttpKernel->handleRaw(object(Request), 1)
in vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php (line 68)
HttpKernel->handle(object(Request), 1, true)
in vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php (line 202)
Kernel->handle(object(Request))
in web/app.php (line 55)

我用来做这个的代码

default.html.php

<div class="post-preview">
    <a href="<?= $this->path('blogpost', [
                    'id' => $blogpost-> getId(),
                    'title' => $blogpost -> getTitle(),
            ]); ?>">

defaultcontroller.php

 public function blogarticleAction($id){
     $this->view->blogarticle = \Pimcore\Model\DataObject\Blogpost::getById($this->getParam("id"));
}

正则表达式设置:

当然,我在与 default.html.php

相同的文件夹中创建了 blogarticle.html.php

使用来自操作的 $id,而不是来自容器的

public function blogarticleAction($id){
     $this->view->blogarticle = \Pimcore\Model\DataObject\Blogpost::getById($id);
}

$this->getParam("id")会在容器中查找一个名为id的参数,这不是你想要的

您应该阅读 https://symfony.com/doc/current/routing.html,其中解释了路由参数