必须定义参数“id”

时间:2018-05-16 09:44:31

标签: php arrays json symfony pimcore

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

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"));
}

RegEx设置:

image

当然,我在与blogarticle.html.php

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

1 个答案:

答案 0 :(得分:0)

从行动中使用$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