![]() |
Base Controller Usage with Flexi Auth - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Base Controller Usage with Flexi Auth (/showthread.php?tid=61903) |
Base Controller Usage with Flexi Auth - itconstruct - 05-29-2015 Hi All, I have already been able to get Flexi Auth working on my codeigniter 3 application however I would like to increase code reuse within my application and reduce duplicate code. As such I was hoping to move the following code contained within my controllers __construct function to a base controller that would be called by each subsequent controller requiring it through extends. The existing code that works is: Controllers except Login.php: PHP Code: function __construct() { Login.php PHP Code: function __construct() { My New Base controller located in the application/core directory: PHP Code: class MY_Controller extends CI_Controller { New Base Controller being called by another controller that extends MY_Controller: PHP Code: function __construct() { Could someone please help me with pointing me in the direction of where I can read up about extending the CI_Controller in Codeigniter 3 and how I should be doing this sort of thing. If anyone has any ideas on what I have done wrong with the above please let me know as I have been trying to look at this for sometime and am still stumped at what I might be missing. Any help is greatly appreciated. RE: Base Controller Usage with Flexi Auth - itconstruct - 05-29-2015 I should add that the errors I am currently getting when trying to run the application are on the login/index page: errors have been truncated: Code: A PHP Error was encountered and Message: Undefined property: stdClass::$session_data RE: Base Controller Usage with Flexi Auth - mwhitney - 05-29-2015 Try changing this: Code: parent::is_logged_in_user_admin(); Code: $this->is_logged_in_user_admin(); Additionally, if you're going to need the auth property defined before loading the flexi_auth library, you might as well define it in your base controller. I would also move loading the library into the base controller, but you might want to put it into a method (possibly along with the definition of the auth property). Then you could call the method conditionally, depending on whether you are using authentication in the current controller. RE: Base Controller Usage with Flexi Auth - itconstruct - 05-29-2015 Hi MWhitney, Thank you very much for your response it has fixed this issue! The additional note is also very helpful and I will take a look at my code to see which approach is more beneficial at this stage. |