Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Why can't I access SimpleGroup after extending SimpleAuth?
  • I'm trying to get the name of a group based on the group number. I've built a driver called LoupeAuth that extends SimpleAuth, and I added the following to /fuel/app/bootstrap.php:

    Autoloader::add_classes(array(
      'Auth_Login_LoupeAuth' => APPPATH.'classes/auth/login/loupeauth.php'
    ));

    My create, update and delete user methods work flawlessly. I don't need to extend the functionality of the SimpleGroup or SimpleAcl, as the default functionality is fine for my needs. However, when I try to call the SimpleGroup method get_name($group), I'm unable to. Specifically, when I try to call:

      \Auth::get_name(80);

    I'm getting this error:

      BadMethodCallException [ Error ]: Invalid method: Auth\Auth::get_name

    If I try:

      \Auth::instance('simplegroup')->get_name(80);

    I get the error:

      ErrorException [ Error ]: Call to a member function get_name() on a non-object

    If I try:

      \Auth\Auth_Group_SimpleGroup::get_name(80);

    I get the error:

      ErrorException [ Runtime Notice ]: Non-static method Auth\Auth_Group_SimpleGroup::get_name() should not be called statically, assuming $this from incompatible context

    If I try:

      $group = new \Auth\Auth_Group_SimpleGroup;
      $group_name = $group->get_name(80);

    I get the error:

      ErrorException [ Error ]: Call to protected Auth\Auth_Driver::__construct() from context 'Controller\Admin_Users'

    I could easily setup a function within my controller that resolves the group name based on hard-coded group definitions, but I'd rather do it the "right" way, so that if group definitions change in the future, I don't have to modify my controller. Am I way off base here?
  • HarroHarro
    Accepted Answer
    \Auth::group()->get_name();

    You can use the driver type to access the driver. For acl, use \Auth::acl()-> ...
  • Side note: if you want to get the name of an arbitrary group, this works:

    \Auth::group()->get_name($group_number);

    This will not:

    \Auth::group($group_number)->get_name();
  • Correct, group() refers to the static interface on the group driver, it's not a method in itself.
  • Why there is nothing about this method in the manual? I have lost about 2 days searching answer, d'oh! >:-\
  • Because the Auth author didn't document anything. And he isn't around to kick anymore.

    I did my best to document it through reverse engineering, but obviously I missed stuff. Feel free to clone the repo, make the changes, and send a pull request.

Howdy, Stranger!

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

In this Discussion