我需要覆盖sylius_partial_product_latest
路由的行为才能使用附加参数渲染模板。
简单的例子:在不同的页面上,我需要一次显示 2 到 4 个产品,轮播滚动浏览 4-8 个产品。现在在SyliusWebBundle:Frontend/Product:latest
模板中我有:
{{ grid(products) }}
但在某些情况下我需要:
{{ grid(products, 2) }}
在其他方面:
{{ grid(products, 3) }}
{# or it can be 4 or any other number #}
现在在模板中我只有products
var (它由资源机制提供服务),我可以将变量传递到存储库,在那里我可以将它添加到我的products
数组中,但这不是一个好方法。它可以通过简单地将变量传递给查询来完成:
{{ render(url('sylius_partial_product_latest', {'size': 3, 'limit': 2, 'template': 'SyliusWebBundle:Frontend/Product:latest.html.twig'})) }}
我需要能够将变量传递size
给.SyliusWebBundle:Frontend/Product:latest
products
我尝试覆盖ProductBundle
and ResourceBundle
... 但是用自定义操作覆盖控制器(我不想覆盖indexAction
or showAction
)让我无处可去。PHP 根本没有击中我的控制器。相反,它击中showAction
了ResourceBundle
. 而且,是的,我覆盖了路由以指向我的控制器。
如果我用新路由覆盖ProductController
并在我的模板中使用它,则会引发异常:
在第 136 行的 SyliusWebBundle:Frontend/Product:show.html.twig 中呈现模板期间引发了异常(“控制器“sylius.controller.product:partialAction” for URI“/partial”不可调用。”) .
当我更改_controller
为以标准 Symfony 方式指向我的控制器时,我有下一个异常:
可捕获的致命错误:传递给 Sylius\Bundle\ResourceBundle\Controller\ResourceController::__construct() 的参数 1 必须是 Sylius\Bundle\ResourceBundle\Controller\Configuration 的实例,未给出,在 /Users/mihail/Sites/magazin 中调用/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerResolver.php 在第 77 行并在 /Users/mihail/Sites/magazin/vendor/sylius/sylius/src/Sylius/Bundle/ResourceBundle/Controller 中定义/ResourceController.php 第 63 行