Symfony2 og dens formbuilder

stemmer
2

Så, jeg vet at dette bare er i beta akkurat nå, men vi har gjort beslutningen om å fortsette med dette i stedet for en.

Så, jeg har fått denne koden

 $this->em = $this->get('doctrine.orm.entity_manager');
 $user = $this->em->find('BlahBlahBundle:User', $id);
 $dql = SELECT r FROM \Blah\BlahBundle\Entity\Role r;
 if($user->getRole()->getRoleId() != '4')
       $dql .=  WHERE r.roleId != '4';
 $rs = $this->em->createQuery($dql)->getResult();
 $roles = array();
 foreach($rs as $item)
       $roles[$item->getRoleId()] = $item->getName();

 $userRole = $user->getRole()->getRoleId();

 $radio = array('0' => 'No', '1' => 'yes');
 $form = $this->buildForm('User', $user)
              ->add('ScreenName')
              ->add('Email')
              ->add('Password','password', array('required' => false))
              ->add('Enabled', 'choice', array('choices' => $radio))
              ->add('AllowedOutside', 'choice', array('choices' => $radio))
              ->add('Role', 'choice', array( 'choices' => $roles, 'preferred_choices' => array($userRole)));
 $form = $form->getForm();

Og alltid dø når jeg prøver å getForm()Når jeg fjerne 'rolle' det fungerer.

I vår database struktur Roller er en annen enhet enn brukere, men de refererer til dem over en fremmednøkkel

feil im gitt når jeg prøver og samtale getForm()er dette

Notice: Object of class Proxies\BlahBlahBundleEntityRoleProxy could not be converted to int in /mnt/www/reportings/vendor/symfony/src/Symfony/Component/Form/Util/FormUtil.php on line 18

Call Stack:
    0.0010     638064   1. {main}() /mnt/www/reportings/web/app_dev.php:0
    0.0374    1859640   2. Symfony\Component\HttpKernel\Kernel->handle() /mnt/www/reportings/web/app_dev.php:13
    0.0476    2073904   3. Symfony\Bundle\FrameworkBundle\HttpKernel->handle() /mnt/www/reportings/app/bootstrap.php.cache:613
    0.0477    2074912   4. Symfony\Component\HttpKernel\HttpKernel->handle() /mnt/www/reportings/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php:35
    0.0478    2074912   5. Symfony\Component\HttpKernel\HttpKernel->handleRaw() /mnt/www/reportings/app/bootstrap.php.cache:420
    0.1955    3938880   6. call_user_func_array() /mnt/www/reportings/app/bootstrap.php.cache:442
    0.1955    3939368   7. Blah\BlahBundle\Controller\UserController->editAction() /mnt/www/reportings/app/bootstrap.php.cache:442
    0.2696    5721072   8. Symfony\Component\Form\FormBuilder->getForm() /mnt/www/reportings/src/Blah/BlahBundle/Controller/UserController.php:51
    0.3463    6520408   9. Symfony\Component\Form\Form->setData() /mnt/www/reportings/vendor/symfony/src/Symfony/Component/Form/FormBuilder.php:454
    0.3465    6521136  10. Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper->mapDataToForms() /mnt/www/reportings/vendor/symfony/src/Symfony/Component/Form/Form.php:378
    0.3523    6543648  11. Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper->mapDataToForm() /mnt/www/reportings/vendor/symfony/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php:47
    0.3529    6543648  12. Symfony\Component\Form\Form->setData() /mnt/www/reportings/vendor/symfony/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php:56
    0.3531    6544512  13. Symfony\Component\Form\Form->normToClient() /mnt/www/reportings/vendor/symfony/src/Symfony/Component/Form/Form.php:369
    0.3531    6544512  14. Symfony\Component\Form\Extension\Core\DataTransformer\ScalarToChoiceTransformer->transform() /mnt/www/reportings/vendor/symfony/src/Symfony/Component/Form/Form.php:898
    0.3531    6544512  15. Symfony\Component\Form\Util\FormUtil::toArrayKey() /mnt/www/reportings/vendor/symfony/src/Symfony/Component/Form/Extension/Core/DataTransformer/ScalarToChoiceTransformer.php:21


Catchable fatal error: Object of class Proxies\BlahBlahBundleEntityRoleProxy could not be converted to string in /mnt/www/reportings/vendor/symfony/src/Symfony/Component/Form/Util/FormUtil.php on line 18

Call Stack:
    0.0010     638064   1. {main}() /mnt/www/reportings/web/app_dev.php:0
    0.0374    1859640   2. Symfony\Component\HttpKernel\Kernel->handle() /mnt/www/reportings/web/app_dev.php:13
    0.0476    2073904   3. Symfony\Bundle\FrameworkBundle\HttpKernel->handle() /mnt/www/reportings/app/bootstrap.php.cache:613
    0.0477    2074912   4. Symfony\Component\HttpKernel\HttpKernel->handle() /mnt/www/reportings/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php:35
    0.0478    2074912   5. Symfony\Component\HttpKernel\HttpKernel->handleRaw() /mnt/www/reportings/app/bootstrap.php.cache:420
    0.1955    3938880   6. call_user_func_array() /mnt/www/reportings/app/bootstrap.php.cache:442
    0.1955    3939368   7. Blah\BlahBundle\Controller\UserController->editAction() /mnt/www/reportings/app/bootstrap.php.cache:442
    0.2696    5721072   8. Symfony\Component\Form\FormBuilder->getForm() /mnt/www/reportings/src/Blah/BlahBundle/Controller/UserController.php:51
    0.3463    6520408   9. Symfony\Component\Form\Form->setData() /mnt/www/reportings/vendor/symfony/src/Symfony/Component/Form/FormBuilder.php:454
    0.3465    6521136  10. Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper->mapDataToForms() /mnt/www/reportings/vendor/symfony/src/Symfony/Component/Form/Form.php:378
    0.3523    6543648  11. Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper->mapDataToForm() /mnt/www/reportings/vendor/symfony/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php:47
    0.3529    6543648  12. Symfony\Component\Form\Form->setData() /mnt/www/reportings/vendor/symfony/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php:56
    0.3531    6544512  13. Symfony\Component\Form\Form->normToClient() /mnt/www/reportings/vendor/symfony/src/Symfony/Component/Form/Form.php:369
    0.3531    6544512  14. Symfony\Component\Form\Extension\Core\DataTransformer\ScalarToChoiceTransformer->transform() /mnt/www/reportings/vendor/symfony/src/Symfony/Component/Form/Form.php:898
    0.3531    6544512  15. Symfony\Component\Form\Util\FormUtil::toArrayKey() /mnt/www/reportings/vendor/symfony/src/Symfony/Component/Form/Extension/Core/DataTransformer/ScalarToChoiceTransformer.php:21

does noen har noen anelse om hvordan jeg kan fikse det?

Publisert på 09/05/2011 klokken 22:58
kilden bruker
På andre språk...                            


1 svar

stemmer
3

Problemet er når symfony skjema komponent prøver å få den nåværende verdien av rollen (ved å gjøre $user->getRole()) det blir læren proxy objekt i stedet for et heltall. For å si det forstår rollen objektet du trenger for å lage en ny form type.

Her er det blant annet i manualen hvordan du bruker dem sammen med bruker form ved hjelp av innebygde skjemaer . (Product == Bruker, Kategori == rolle).

Svarte 09/05/2011 kl. 23:26
kilden bruker

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more