【问题标题】:Sylius\Bundle\TaxonomiesBundle\Doctrine\ORM\TaxonRepository::getTaxonsAsList()Sylius\Bundle\TaxonomiesBundle\Doctrine\ORM\TaxonRepository::getTaxonsAsList()
【发布时间】:2014-08-06 08:00:16
【问题描述】:

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

可捕获的致命错误:参数 1 传递给 Sylius\Bundle\TaxonomiesBundle\Doctrine\ORM\TaxonRepository::getTaxonsAsList() 必须实现接口 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()
    ;
}

}

你能帮帮我吗,非常感谢

【问题讨论】:

    标签: php symfony sylius


    【解决方案1】:

    我使用独立包。我也遇到了同样的问题。

    我通过在我的分类类的构造函数中添加“$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());
        }
    }
    

    类分类群

    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
    {
    }
    

    【讨论】:

      【解决方案2】:

      我遇到了完全相同的问题。

      我也确实覆盖了 TaxonomyBundle 中的模型。并且还将 setRoot 方法放置在分类法的构造函数中。它实际上确实修复了一个错误,但没有修复上面描述的错误。

      问题是加载了 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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-05-18
        • 1970-01-01
        • 1970-01-01
        • 2011-10-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-06-27
        相关资源
        最近更新 更多