我正在使用扩展它的FOSUserBundle 1.3和SonataUserBundle。我有自己的捆绑包,扩展了SonataUserBundle,在其中我保留了我的用户管理类和用户&用户组实体(以及相关的.orm.xml映射)
我的config.yml:
parameters:
sonata.user.admin.user.entity: Acme\Bundle\UserBundle\Entity\User
sonata.user.admin.group.entity: Acme\Bundle\UserBundle\Entity\Group
sonata.user.admin.user.class: Acme\Bundle\UserBundle\Admin\UserAdmin
fos_user:
db_driver: orm
firewall_name: main
user_class: Acme\Bundle\UserBundle\Entity\User
group:
group_class: Acme\Bundle\UserBundle\Entity\Group
group_manager: sonata.user.orm.group_manager
service:
user_manager: sonata.user.orm.user_manager
两个实体类基本上只是扩展了Sonata的用户和组类。我的用户管理类扩展了Sonata \ UserBundle \ Admin \ Entity \ UserAdmin。
问题是在我的/ admin中,当我列出用户时,我收到错误:
注意:未定义的索引:组中的 /vagrant/vendor/sonata-project/doctrine-orm-admin-bundle/Guesser/FilterTypeGuesser.php 第64行
答案 0 :(得分:4)
编辑:正如@Hemang指出的那样,我的第一个答案并非如此明确。所以我纠正了它
为了获得用户实体的正确映射,您必须启用SonataEasyExtendsBundle。
为此,请编辑您的AppKernel.php并添加行
new Sonata\EasyExtendsBundle\SonataEasyExtendsBundle()
在registerBundles函数中。
这是一个有效的AppKernel.php例子:
<?php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new Knp\Bundle\MenuBundle\KnpMenuBundle(),
new Ivory\CKEditorBundle\IvoryCKEditorBundle(),
new FOS\UserBundle\FOSUserBundle(),
new Sonata\CoreBundle\SonataCoreBundle(),
new Sonata\BlockBundle\SonataBlockBundle(),
new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
new Sonata\AdminBundle\SonataAdminBundle(),
new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'),
new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),
new Sonata\EasyExtendsBundle\SonataEasyExtendsBundle(),
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
return $bundles;
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__ . '/config/config_' . $this->getEnvironment() . '.yml');
}
}
答案 1 :(得分:0)
我遇到同样的麻烦...我认为奏鸣曲用户配置器没有注册学说映射...... https://github.com/sonata-project/SonataUserBundle/blob/master/DependencyInjection/SonataUserExtension.php#L249
作为解决方法,我添加了与自定义用户实体的多对多关系
namespace Acme\Bundle\UserBundle\Entity
class User
{
...
/**
* @ORM\ManyToMany(targetEntity="Group")
* @ORM\JoinTable(name="fos_user_user_group")
*/
protected $groups;
}