Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Where to put Simpleauth's subclass file
I am trying to subclass simpleauth login driver to add Remember me option. Where should I put the file?
Hi Jelmer! I'm trying to implement option #2 that you described above (thank you for the very clear instructions), but I keep getting an undefined method error. I must be doing something wrong - I hope you (or someone) can help. I did everything you said to go in #2 above :
- I created app/classes/auth/login/simpleauth.php
- The class definition is Auth_Login_SimpleAuth extends Auth\Auth_Login_SimpleAuth
- there's no namespace defined and there's only one function in it - create_verify_code I haven't modified any config files. My auth config lists SimpleAuth as the only driver. In a model, I get an auth instance like so : $auth = Auth::instance(); When I call, $auth->create_verify_code(), I get an undefined method error : ErrorException [ Error ]: Call to undefined method Auth\Auth_Login_SimpleAuth::create_verify_code()
I feel like I must be doing something wrong and it's probably silly and obvious... Thank you for any help!
Ah, stupid me - I forgot one instruction. As the Auth namespace is considered a core namespace you cannot implicitly overwrite the "core" auth class. Thus you have to make it explicit by adding Auth_Login_SimpleAuth to your app/bootstrap.php file. There's already an example in there for the View class: // 'View' => APPPATH.'classes/view.php', It works the same for this one: 'Auth_Login_SimpleAuth' => APPPATH.'classes/auth/login/simpleauth.php', - add that to the array in the Autoloader::add_classes() method call.
Ah yes!! That fixed! Thanks so much for your help!
Whereever you like. I use it in 2 ways: new drivers in a package and extending SimpleAuth in the app: 1. New drivers in a package
For example the class MyAuth\Auth_Login_MyAuth is at fuel/packages/myauth/auth/login/myauth.php and registered in a config file in app/config/auth.php that has 'driver' => 'MyAuth\\MyAuth' in it. (the base driver will rewrite that to MyAuth\Auth_Login_MyAuth) (though actually I have it 'driver' => 'MyAuth' and the MyAuth package is defined as a core extension in the bootstrap to allow me extension in the app for different projects) 2. SimpleAuth extension
This one won't need to change the config. Just add a class Auth_Login_SimpleAuth without a namespace in app/classes/auth/login/simpleauth.php and extend Auth\Auth_Login_SimpleAuth and add the stuff you need.
[EDIT:] As the Auth namespace is a core namespace you will have to add this class to the app/bootstrap.php file to make it explicit that you are overwriting the Auth_Login_SimpleAuth class. Add: 'Auth_Login_SimpleAuth' => APPPATH.'classes/auth/login/simpleauth.php'
Thank Jelmer. Hope I can make it work!
Add a Comment
It looks like you're new here. If you want to get involved, click one of these buttons!
Apply for Membership
↳ Job Board
↳ Installation & Setup
↳ Tips and Tutorials
↳ Code share
In this Discussion