CoreShop 4 - Extending Frontend Controllers #2637
Closed
Stefan-JustMe69-SQ
started this conversation in
General
Replies: 11 comments 2 replies
|
You don't need to extend from the FrontendController and use parameter injection instead. |
0 replies
|
Example somewhere? |
1 reply
|
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 |
0 replies
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 |
0 replies
|
tried: |
0 replies
|
ah sorry, extend from FrontendController and not BaseIndexController |
0 replies
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]);
}
} |
1 reply
|
Sorry, |
0 replies
|
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. |
0 replies
|
@dpfaffenbauer please mark my last comment as accepted answer and this discussion as resolved if it's fine with you, thanks. |
0 replies
|
thanks @JustMe69 |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment


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?
All reactions