Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
simplegroup - getting group id from group name?
  • I feel like I'm probably missing something obvious! Is there a way to get a group's id from the group's name? Say I want to assign a user to a group. I'd rather do something like :
    $user->group = Auth::group->get_id( 'coordinators' );
    $user->save();
    
    As far as I can tell, there's nothing like that. It seems the easiest way to assign a user to a group is just to change the value of $user->group to the group's id itself. But using the group name is much more readable, I think. The only way I can think of to do this is to grab the groups from the simpleauth config file and loop through them to match the name and get the id. Is there a better way? Thanks for any help!
  • Auth::group is a method. The correct way is: $user->group = Auth::group()->get_id( 'coordinators' );
    $user->save(); I'm a new user of Fuelphp and I noticed that the documentation is not enough. I hope to help and be helped. (sorry for my english, I speak spanish)
  • That this works is a by-product of the __callStatic() method in the Auth class, in combination with the fact that you only have one group driver loaded. Having said that, we are absolutely aware that the docs can be improved. If you see something is missing, send us a pull request with the additions, or create an issue for it at http://github.com/fuel/docs/issues, since remarks here are easily forgotten...

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion