When I try to access my subpage, this error pops-out
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)
Code I used to do this
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 set up:
ofcourse I created blogarticle.html.php
in the same folder as default.html.php
Use $id
from action, not from container
public function blogarticleAction($id){
$this->view->blogarticle = \Pimcore\Model\DataObject\Blogpost::getById($id);
}
$this->getParam("id")
Will look in the container a parameter named id
, which is not what you want
You should read https://symfony.com/doc/current/routing.html which explains about route parameters