Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Problem with Auth::get_roles() in MyAuth SimpleAuth replacement
  • I'm writing a (pretty much) drop-in replacement for SimpleAuth, but I seem to be missing something.

    Calling Auth::get_roles() throws an exception "BadMethodCallException [ Error ]: Invalid method: Auth\Auth::get_roles from Auth::__callStatic()."

    Trying to investigate it, it seems that:
    - calling Auth::login() works fine as it finds a login method in Auth_Login_MyAuth
    - calling Auth::member() work fine (due to 'member' existing in $_drivers?)
    - calling Auth::get_roles fails, as far as I can see because there is no 'get_roles' method in Auth_Login_MyAuth? (it is in Auth_Group_MyAuth)

    Can anyone suggest where I'm going wrong?

    Thanks, Chris
  • You do have multiple drivers active? The static calls only work if there is only one driver present.
  • Is 'drivers' like SimpleAuth? I just have the one 'MyAuth' (as far as I know! - can I check?). The Auth::login() and Auth::member() are working fine, so I suppose I just have the MyAuth driver? Thanks.
  • You can't call get_roles in the default Auth installation too.

    A quick scan of the code reveals you can only call methods in the Login driver statically, as the methods are called on the Auth instance. The Group and ACL drivers are properties of the Login driver, and no separate instance in Auth.

    To access methods in the Group driver (providing you have only one driver loaded), you can use
    $roles = Auth::group()->get_roles();
    to get the roles of the current logged in user.
  • Harro, you are a star! I think we all appreciate the work you put into this forum.

    That makes sense, that get_roles() should be accessed through the group(), I just hadn't found it anywhere in my searching.

    BTW, would you have any suggestion as to why I keep having 'index.php' appear in the URL when I do Response::redirect()?

    Thanks, Chris
  • HarroHarro
    Accepted Answer
    Because you haven't disabled it in your app/config/config.php? Set "index_file" to false.
  • Doh! I was sure I'd done that already! – something gone wrong in the 1.3 -> 1.4 upgrade perhaps, between local & remote servers, I dunno...

    Thanks again!

Howdy, Stranger!

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

In this Discussion