我是否需要在symfony2中的'group'和'role'类中添加'users'类?

I have these classes:

user.php, group.php and role.php

Now, the group class has "M to M with users" and also "M to M with roles".

I am not sure if I need to add users in the role class or not, because users will belong to group and group will belong to roles.

If I understood you corectly you have something like this:

user M2M group group M2M role

So, you probably want to split roles (in Symfony way) in some groups. If you want to do something like that, could you follow the Symfony cookbook until you get user + role working and then just add some relation between roles and groups or simply make a constant class, list your constants and add them to roles as a filed and let your controller handle the rest, when needed.

If you need something else then I misunderstood you but anyway... I would say that Symfony wants you to define user and roles and that's it and the framework will not ask you about possible other data and/or relations you have integrated in user and/or roles.

I hope I was helpfull, sorry if I missunderstood your question.

Best regards