CoreShop 4 - Extending Frontend Controllers #2637
Replies: 11 comments 2 replies
-
|
You don't need to extend from the FrontendController and use parameter injection instead. |
Beta Was this translation helpful? Give feedback.
-
|
Example somewhere? |
Beta Was this translation helpful? Give feedback.
-
|
same error with use CoreShop\Bundle\FrontendBundle\Controller\IndexController as BaseController;
use CoreShop\Bundle\FrontendBundle\TemplateConfigurator\TemplateConfiguratorInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class IndexController extends BaseController
{
public function __construct(protected TemplateConfiguratorInterface $templateConfigurator, protected $container)
{
parent::__construct($this->container);
}
and |
Beta Was this translation helpful? Give feedback.
-
use CoreShop\Bundle\FrontendBundle\Controller\IndexController as BaseController;
use CoreShop\Bundle\FrontendBundle\TemplateConfigurator\TemplateConfiguratorInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class IndexController extends BaseController
{
public function indexAction(Request $request, TemplateConfiguratorInterface $templateConfigurator): Response
{
return $this->render($templateConfigurator->findTemplate('Index/index.html'));
}try it like this |
Beta Was this translation helpful? Give feedback.
-
|
tried: |
Beta Was this translation helpful? Give feedback.
-
|
ah sorry, extend from FrontendController and not BaseIndexController |
Beta Was this translation helpful? Give feedback.
-
use CoreShop\Bundle\FrontendBundle\Controller\FrontendController;
use CoreShop\Bundle\FrontendBundle\TemplateConfigurator\TemplateConfiguratorInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class IndexController extends FrontendController
{
public function __construct(protected TemplateConfiguratorInterface $templateConfigurator, protected $container)
{
parent::__construct($this->container);
}
public function indexAction(Request $request, TemplateConfiguratorInterface $templateConfigurator): Response
{
// return $this->render($this->getTemplateConfigurator()->findTemplate('Index/index.html'));
return $this->render($this->getTemplateConfigurator()->findTemplate('Index/index.html'), ['is_home' => true]);
// return $this->render('Index/index.html.twig', ['is_home' => true]);
}
} |
Beta Was this translation helpful? Give feedback.
-
|
Sorry, |
Beta Was this translation helpful? Give feedback.
-
|
I have the solution Docs saying for own class 'TemplateConfigurator' configuration is needed as followed: I have to use: Without the first 3 lines of configuration above, error is always shown: Now frontend is showing up, with own IndexController: <?php
declare(strict_types=1);
namespace FrontendBundle\CoreShop\Controller;
use CoreShop\Bundle\FrontendBundle\Controller\FrontendController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class IndexController extends FrontendController
{
public function indexAction(Request $request): Response
{
return $this->render($this->getTemplateConfigurator()->findTemplate('Index/index.html'));
}
}and config: and config: I suggest to change documentation. |
Beta Was this translation helpful? Give feedback.
-
|
@dpfaffenbauer please mark my last comment as accepted answer and this discussion as resolved if it's fine with you, thanks. |
Beta Was this translation helpful? Give feedback.
-
|
thanks @JustMe69 |
Beta Was this translation helpful? Give feedback.


Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I followed documentation
https://docs.coreshop.org/CoreShop/Development/Frontend_Bundle/
an created own class TemplateConfigurator
I created controller IndexController and followed description in
https://docs.coreshop.org/CoreShop/Development/Frontend_Bundle/Controllers
and created controller and configuration as described
my class:
my configs:
I'm getting error:
How to fix that?
Beta Was this translation helpful? Give feedback.
All reactions