简体   繁体   English

symfony 2,用户列表

[英]symfony 2, list of users

I try to do a select with all my users. 我尝试对所有用户进行选择。 An admin has is his part a possibility to change the infos from the users. 管理员可以从用户那里更改信息。 Email adress for example. 例如,电子邮件地址。

I need to do a select with all the users, Then the admin choice a user and then he can change his infos. 我需要对所有用户进行选择,然后管理员选择一个用户,然后他可以更改其信息。

How can I do that? 我怎样才能做到这一点?

Thanks Best regards 最好的问候

I tried to do so: 我试图这样做:

<?php
 
namespace gestEntrSym\gestBundle\Form;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\AbstractType;
 
class entrainementGroupeForm extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
 
       $userManager = $this->get('fos_user.user_manager');
        $users = $userManager->findUsers();
        $builder
            ->add('date');
    }
 
    public function getName()
    {
        return 'entrainementGroupe';
    }
}

Then I have this error: 然后我有这个错误:

Attempted to call method "get" on class "gestEntrSym\\gestBundle\\Form\\entrainementGroupeForm" in C:\\Users\\ale252\\Dropbox\\wamp\\www\\gestEntrSym\\src\\gestEntrSym\\gestBundle\\Form\\entrainementGroupeForm.php line 12. Did you mean to call: "getName", "getParent"? 尝试在C:\\ Users \\ ale252 \\ Dropbox \\ wamp \\ www \\ gestEntrSym \\ src \\ gestEntrSym \\ gestBundle \\ Form \\ entrainementGroupeForm.php第12行的类“ gestEntrSym \\ gestBundle \\ Form \\ entrainementGroupeForm”上调用方法“ get”意味着要调用:“ getName”,“ getParent”?

My idea is to take the users array to do a foreach and do a $builder->add('date') for all the values of the array. 我的想法是让users数组执行foreach并对数组的所有值执行$ builder-> add('date')。

This is just a try with a date type, then I can do the same with a choice type. 这只是尝试使用日期类型,然后我可以对选择类型进行相同的操作。


I have done anything like that: 我做了这样的事情:

<?php
 
namespace gestEntrSym\gestBundle\Form;
 
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\AbstractType;
use Doctrine\ORM\EntityManager;
use gestEntrSym\UserBundle\Entity\User;
 
class entrainementGroupeForm extends AbstractType {
 
    /**
     * The entity manager
     *
     * @var EntityManager
     */
    private $users;
 
    /**
     * @param EntityManager
     */
    public function __construct($users) {
        $this->users = $users;
    }
 
    public function buildForm(FormBuilderInterface $builder, array $options) {
 
 
        foreach ($this->users as $value) {
//            var_dump($value);
//            exit;
            $builder->add('public', 'checkbox', array(
                'label' => $value->getNom(),
                'required' => false,
            ));
        }
    }
 
    public function getName() {
        return 'entrainementGroupe';
    }
 
}

Then in my controller: 然后在我的控制器中:

$userManager = $this->get('fos_user.user_manager');
        $users = $userManager->findUsers();
 
        $entrainementGroupe = new entrainementGroupe();
//        var_dump($users[0]);
//        exit;
        $form = $this->createForm(new entrainementGroupeForm($users), $entrainementGroupe);

But I have always an error: 但是我总是有一个错误:

Neither the property "public" nor one of the methods "getPublic()", "public()", "isPublic()", "hasPublic()", "__get()" exist and have public access in class "gestEntrSym\\gestBundle\\Entity\\entrainementGroupe". 属性“ public”或方法“ getPublic()”,“ public()”,“ isPublic()”,“ hasPublic()”,“ __ get()”都不存在,并且在“ gestEntrSym \\”类中具有公共访问权限gestBundle \\ Entity \\ entrainementGroupe”。

Somebody knows why? 有人知道为什么吗?

Thanks 谢谢

if you want to have a form with all the users (100) and for each a date - this wouldn't be convenient, so if you want to modify just one user's info, you can use the same "load all users" from the "Basic usage" and on user select from the dropdown you load the user data in the fields ( date, id,name and so on) , modify the required ones, click save and when clicking save in the controller/model you will get the user you have "choosen" and the data for it 如果您想拥有一个包含所有用户的表单(100),并且每个日期都有一个日期-这将不方便,因此,如果您只想修改一个用户的信息,则可以使用相同的“加载所有用户” “基本用法”并在用户选择的下拉菜单中,将用户数据加载到字段中(日期,ID,名称等),修改所需的数据,单击“保存”,然后在控制器/模型中单击“保存”时,用户,您有“选择”及其数据

here is how you can select all users from the database very easy link , 这是您可以从数据库非常容易的链接中选择所有用户的方法,

here is the link to read how to "listen to the select option and load the data dynamically" in the forn link 这是在Forn 链接中阅读如何“侦听选择选项并动态加载数据”的链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM