Symfony2 FOSUserBundle and groups error

不想你离开。 提交于 2019-12-11 17:59:57

问题


i am getting an error, when applying

php app/console doctrine:schema:update --force

i get a stack of errors, starting with

PHP Fatal error:  Declaration of Tracker\MembersBundle\Entity\User::addGroup() must be 

compatible with that of FOS\UserBundle\Model\GroupableInterface::addGroup() in C:\Program Files (x86)\Zend\Apache2\htdocs\mysite\src\Tracker\MembersBundle\Entity\User.php on line 14
PHP Stack trace:
PHP   1. {main}() C:\Program Files (x86)\Zend\Apache2\htdocs\mysite\app\console:0
PHP   2. Symfony\Component\Console\Application->run() C:\Program Files (x86)\Zend\Apache2\htdocs\mysite\app\console:22
PHP   3. Symfony\Bundle\FrameworkBundle\Console\Application->doRun() C:\Program Files (x86)\Zend\Apache2\htdocs\mysite\vendor\symfony\src\Symfony\Component\Console\Application.php:118
PHP   4. Symfony\Component\Console\Application->doRun() C:\Program Files (x86)\Zend\Apache2\htdocs\mysite\vendor\symfony\src\Symfony\Bundle\FrameworkBundle\Console\Application.php:75

i figured out User::addGroup() and the groups implementation of FOSUserBundle ...but i do not know how to ultimately solve it...here are my two entities

User Group

Update: if i simply remove addGroup() from the User Entity, and go to the path http://mysite.com/app_dev.php/group/new i get a fatal error

 Fatal error: Declaration of FOS\UserBundle\Form\Type\GroupFormType::getDefaultOptions() must be compatible with that of Symfony\Component\Form\FormTypeInterface::getDefaultOptions() in C:\Program Files (x86)\Zend\Apache2\htdocs\mysite\vendor\bundles\FOS\UserBundle\Form\Type\GroupFormType.php on line 18

回答1:


You have to add FQCN of GroupableInterface in your User class e.g

use FOS\UserBundle\Model\GroupableInterface;

Edit:

You have to update symfony. As they have changed function signature of getDefaultOptions. Check here.




回答2:


you should remove from:

vendor\yourBundle\Entity\User;

getter setter group function coz it was already declared on

use FOS\UserBundle\Model\User.php;

it can be duplicate function !

now generate your schema i hope it helps you :D



来源:https://stackoverflow.com/questions/10139171/symfony2-fosuserbundle-and-groups-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!