首页 文章

Sylius \包\ TaxonomiesBundle \原则\ ORM \ TaxonRepository :: getTaxonsAsList()

提问于
浏览
0

我下载并安装了SyliusTaxonomiesBundle,当我想创建一个分类单元(链接到分类法)时,我遇到以下问题:

可捕获的致命错误:传递给Sylius \ Bundle \ TaxonomiesBundle \ Doctrine \ ORM \ TaxonRepository :: getTaxonsAsList()的参数1必须实现接口Sylius \ Bundle \ TaxonomiesBundle \ Model \ TaxonomyInterface,null给定,在/ home / jeremy / web / vendor中调用/sylius/taxonomies-bundle/Sylius/Bundle/TaxonomiesBundle/Form/Type/TaxonChoiceType.php在第70行并在/ home / jeremy / web / vendor / sylius / taxonomies-bundle / Sylius / Bundle / TaxonomiesBundle / Doctrine / ORM中定义/TaxonRepository.php第25行

这个级别的问题:https://github.com/pjedrzejewski/SyliusTaxonomiesBundle/blob/master/Form/Type/TaxonChoiceType.php

/**
 * {@inheritdoc}
 */
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
    $repository = $this->taxonRepository;
    $choiceList = function (Options $options) use ($repository) {
        $taxons = $repository->getTaxonsAsList($options['taxonomy']);

        if (null !== $options['filter']) {
            $taxons = array_filter($taxons, $options['filter']);
        }

        return new ObjectChoiceList($taxons);
    };

    $resolver
        ->setDefaults(array(
            'choice_list' => $choiceList
        ))
        ->setRequired(array(
            'taxonomy',
            'filter'
        ))
        ->setAllowedTypes(array(
            'taxonomy' => array('Sylius\Bundle\TaxonomiesBundle\Model\TaxonomyInterface'),
            'filter' => array('\Closure', 'null')
        ))
    ;
}

和getTaxonsAsList方法在这里:https://github.com/pjedrzejewski/SyliusTaxonomiesBundle/blob/master/Doctrine/ORM/TaxonomyRepository.php

class TaxonRepository extends EntityRepository implements TaxonRepositoryInterface
{
public function getTaxonsAsList(TaxonomyInterface $taxonomy)
{
    return $this->getQueryBuilder()
        ->where('o.taxonomy = :taxonomy')
        ->andWhere('o.parent IS NOT NULL')
        ->setParameter('taxonomy', $taxonomy)
        ->orderBy('o.left')
        ->getQuery()
        ->getResult()
    ;
}

}

能帮帮我吗,非常感谢你

2 回答

  • 0

    我使用独立捆绑包 . 我遇到了同样的问题 .

    我通过在我的分类法类的构造函数中添加“$ this-> setRoot(new Taxon())”解决了我的问题 .

    我覆盖了分类学模型和分类单元,它对我有用 .

    use Doctrine\ORM\Mapping as ORM;
    
    use Sylius\Component\Taxonomy\Model\Taxonomy as BaseTaxonomy;
    
    use Syn\CoreBundle\Entity\Taxon;
    /**
     * Class Taxonomy.
     * 
     * @ORM\Table(name="syn_taxonomy")
     * @ORM\Entity
     */
    class Taxonomy extends BaseTaxonomy
    {
        /**
         * {@inheritdoc}
         */
        public function __construct()
        {
            $this->setRoot(new Taxon());
        }
    }
    

    class 分类

    use Doctrine\ORM\Mapping as ORM;
    
    use Sylius\Component\Taxonomy\Model\Taxon as BaseTaxon;
    
    /**
     * Class Taxon.
     * 
     * @ORM\Table(name="syn_taxon")
     * @ORM\Entity
     */
    class Taxon extends BaseTaxon
    {
    }
    
  • 0

    我有完全相同的问题 .

    我也覆盖了TaxonomyBundle中的模型 . 并且还将setRoot方法放置在Taxonomy的构造函数中 . 它确实修复了错误,但没有修复错误,如上所述 .

    问题是加载了syliusResourceController而不是SyliusTaxonController . 您可以通过在控制台中输入 php app/console container:debug | grep taxon 来进行检查

    您可以像这样更改控制器:

    sylius_taxonomy:
        driver: doctrine/orm
        classes:
            taxonomy:
                model: App\CoreBundle\Model\Taxonomy
            taxon:
                controller: Sylius\Bundle\TaxonomyBundle\Controller\TaxonController
                model: App\CoreBundle\Model\Taxon
    

相关问题