User Authentication |
[eluser]cahva[/eluser]
Well I have done it this way: - Create the auth library ![]() - add the auth library to autoload. - Create the controller for the login and logout which has the login form etc. - Now in every controller's construct you would have this: Code: function __construct() I dont think 2 lines of code in every construct is asking too much ![]()
[eluser]John Fuller[/eluser]
You could also run your check login method from a hook.
[eluser]Rick Jolly[/eluser]
[quote author="cahvarno" date="1222471906"] I dont think 2 lines of code in every construct is asking too much ![]() Why do it in every controller when you can do it in one parent controller?
[eluser]Randy Casburn[/eluser]
[quote author="Rick Jolly" date="1222475169"][quote author="cahvarno" date="1222471906"] I dont think 2 lines of code in every construct is asking too much ![]() Why do it in every controller when you can do it in one parent controller?[/quote] And the terror of the darkness flaps and mighty wisdom flows forth!
[eluser]cahva[/eluser]
[quote author="Randy Casburn" date="1222475817"]And the terror of the darkness flaps and mighty wisdom flows forth![/quote] Word! ![]() That was the way I did it in my first CI project and that was the beginning of summer so there might be some things I didnt optimize ![]()
[eluser]Moon 111[/eluser]
cahvarno, I'm sorry to say this, but that is a rather bad idea. What if you need to change it? What if you have 100 controllers? Or 1000? My real question is "How do I create a parent controller, and how do I made it die if the user is not logged in.". For the die, should I just use a redirect?
[eluser]Rick Jolly[/eluser]
Lots of examples of extending the controller on the forums. If you create a MY_Controller.php in your libraries folder, you can put any number of parent controller classes in that file. Here's an example: http://ellislab.com/forums/viewthread/90763/#458617 I prefer to just include/require the parent controller at the top of all extending controllers though: Code: include APPPATH . 'controllers/parents/admin.php'; Use redirect in the authenticating parent's constructor. The CI redirect function calls "exit" after sending the redirect header.
[eluser]Moon 111[/eluser]
Fatal error: Call to undefined method redirect() in C:\wamp\www\CodeIgniter\system\application\libraries\MY_Controller.php on line 51 Code: <?php And my test.php controller is extending AuthUserController. What is wrong with this code?
[eluser]Moon 111[/eluser]
Fatal error: Call to undefined method redirect() in C:\wamp\www\CodeIgniter\system\application\libraries\MY_Controller.php on line 51 Everything besides the redirect works... Why not?
[eluser]Rick Jolly[/eluser]
As with any helper or library in CI, you have to load it. |
Welcome Guest, Not a member yet? Register Sign In |