小编Erv*_*bić的帖子

从 Symfony 中的表单类型访问用户实体

我正在尝试在 Symfony 中构建多租户支持,为此我group_id在我的用户中创建了一个列,最重要的是,所有实体也都有这个相同的列。这样用户只能访问其组的数据。

我已经成功地通过数据访问和显示解决了整个问题,但随后出现了EntityTypesSymfony Forms 的挑战。

问题基本上是,如何EntityType仅显示该特定组输入的数据。按group_id用户和联系人所拥有的进行排序。传递此信息以便用户只能访问其数据的最佳方法是什么?

<?php 

namespace ContactBundle\Form; 

use ContactBundle\Entity\Contact; 
use ContactBundle\Entity\Organization;
use Symfony\Component\Form\AbstractType; 
use Symfony\Component\Form\FormBuilderInterface; 
use Symfony\Component\OptionsResolver\OptionsResolver; 
use Symfony\Component\Form\Extension\Core\Type\TextType; 
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; 

class ContactType extends AbstractType 
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder 
        ->add('first_name', TextType::Class, [
            'attr' => ['class'=>'u-full-width'],
            'label' => 'First Name',])
        ->add('last_name', TextType::Class, [
            'attr' => ['class'=>'u-full-width'],
            'label'=>'Last Name',
        ])
        ->add('email', TextType::Class, [
            'attr' => ['class'=>'u-full-width'],
            'label'=>'Email Address'
        ])
        ->add('organization_id', EntityType::Class, [ …
Run Code Online (Sandbox Code Playgroud)

php multi-tenant symfony fosuserbundle

1
推荐指数
1
解决办法
3502
查看次数

标签 统计

fosuserbundle ×1

multi-tenant ×1

php ×1

symfony ×1