Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Sylius:无法将产品列表嵌入视图/自定义存储库_Php_Symfony_Sylius - Fatal编程技术网

Php Sylius:无法将产品列表嵌入视图/自定义存储库

Php Sylius:无法将产品列表嵌入视图/自定义存储库,php,symfony,sylius,Php,Symfony,Sylius,我想将产品列表嵌入到视图中,如文档中所述: (另见:) 我复制并粘贴了上面页面的大部分代码片段。我使用文档中的代码生成了文件src/AppBundle/Repository/ProductRepository.php: <?php namespace AppBundle\Repository; use Sylius\Bundle\CoreBundle\Doctrine\ORM\ProductRepository as BaseProductRepository; use Sylius\

我想将产品列表嵌入到视图中,如文档中所述: (另见:)

我复制并粘贴了上面页面的大部分代码片段。我使用文档中的代码生成了文件
src/AppBundle/Repository/ProductRepository.php

<?php

namespace AppBundle\Repository;

use Sylius\Bundle\CoreBundle\Doctrine\ORM\ProductRepository as BaseProductRepository;
use Sylius\Component\Core\Model\ChannelInterface;

class ProductRepository extends BaseProductRepository
{
    /**
     * {@inheritdoc}
     */
    public function findLatestByChannelAndTaxonCode(ChannelInterface $channel, $code, $count)
    {
        return $this->createQueryBuilder('o')
            ->innerJoin('o.channels', 'channel')
            ->addOrderBy('o.createdAt', 'desc')
            ->andWhere('o.enabled = true')
            ->andWhere('channel = :channel')
            ->innerJoin('o.taxons', 'taxon')
            ->andWhere('taxon.code = :code')
            ->setParameter('channel', $channel)
            ->setParameter('code', $code)
            ->setMaxResults($count)
            ->getQuery()
            ->getResult()
        ;
    }
}
我在
app/config/routing.yml
(1:1复制和粘贴)中配置了路由

然后我希望它在我的index.html.twig中呈现:

<h2 class="ui horizontal section divider header">My custom title</h2>

{{ render(url('app_shop_partial_product_index_latest_by_taxon_code', {'code': 'mugs', 'count': 4, 'template': '@SyliusShop/Product/_horizontalList.html.twig'})) }}
我的自定义标题
{呈现(url('app_shop_partial_product_index_latest_by_taxon_code',{'code':'mugs','count':4,'template':'@SyliusShop/product/_horizontalList.html.twig')}
标题是可见的,我使用的是样本数据,因此有一个代码为“mugs”的现有分类单元。但是没有可见的产品列表

我在文档中跳过了什么吗?我是Symfony的新手,所以也许我忘了一些明显的事情?我如何自己调试呢


编辑:当前版本的文档已经过时,请参见

productTaxon有一个新概念,因此正确的功能是:

public function findLatestByChannelAndTaxonCode(ChannelInterface $channel, $code, $count)
        {
            return $this->createQueryBuilder('o')
                ->innerJoin('o.channels', 'channel')
                ->andWhere('o.enabled = true')
                ->andWhere('channel = :channel')
                ->innerJoin('o.productTaxons', 'productTaxons')
                ->addOrderBy('productTaxons.position', 'asc')
                ->innerJoin('productTaxons.taxon', 'taxon')
                ->andWhere('taxon.code = :code')
                ->setParameter('code', $code)
                ->setParameter('channel', $channel)
                ->setMaxResults($count)
                ->getQuery()
                ->getResult();
        }
报告也得到了更新

<h2 class="ui horizontal section divider header">My custom title</h2>

{{ render(url('app_shop_partial_product_index_latest_by_taxon_code', {'code': 'mugs', 'count': 4, 'template': '@SyliusShop/Product/_horizontalList.html.twig'})) }}
public function findLatestByChannelAndTaxonCode(ChannelInterface $channel, $code, $count)
        {
            return $this->createQueryBuilder('o')
                ->innerJoin('o.channels', 'channel')
                ->andWhere('o.enabled = true')
                ->andWhere('channel = :channel')
                ->innerJoin('o.productTaxons', 'productTaxons')
                ->addOrderBy('productTaxons.position', 'asc')
                ->innerJoin('productTaxons.taxon', 'taxon')
                ->andWhere('taxon.code = :code')
                ->setParameter('code', $code)
                ->setParameter('channel', $channel)
                ->setMaxResults($count)
                ->getQuery()
                ->getResult();
        }