Autoload problem |
[eluser]weedy[/eluser]
EDIT: Solved, see post #4 for info. http://ellislab.com/forums/viewthread/79175/#397322 I put core session class to autoload, it works in a pre-controller hook, but calling it in the controller results in "Message: Undefined property: User::$session" and "Fatal error: Call to a member function userdata() on a non-object in /usr/local/www/casting/system/application/controllers/user.php on line 21". Any ideas what might be causing it? (and yes I'm a CI newb) Below the code: config.php Code: $autoload['libraries'] = array('database', 'session'); hooks.php Code: $hook['pre_controller'][] = array( hooks/auth.php Code: class Auth extends Controller controllers/user (constructor is blank apart from parent::Controller call) Code: function login()
[eluser]wiredesignz[/eluser]
Autoload occurs in the Controller constructor, and because you are using the pre-controller hook, autoload has not yet run. get_instance() will also fail if the Controller is not instaniated yet.
[eluser]weedy[/eluser]
Well, hook DOES work WITH preloaded stuff (uri, session classes and url helper) without problem, it's the controller that fails.
[eluser]weedy[/eluser]
Basically, for some reason my User class, which extends Controller class appears to not have $this->session although the log says session has been initialized (and when I try to add another init it says that I am attempting to init it twice and the second instance is ignored).
[eluser]weedy[/eluser]
Problem solved - CodeIgniter doesn't support extending Controller twice per request (or so does it seem) - I extended Controller with Auth and then tried to do the same with User - I ended up making the auth hook a function which worked post-controller and all conflicts were resolved.
[eluser]garaget[/eluser]
[quote author="weedy" date="1210534947"]Problem solved - CodeIgniter doesn't support extending Controller twice per request (or so does it seem) - I extended Controller with Auth and then tried to do the same with User - I ended up making the auth hook a function which worked post-controller and all conflicts were resolved. [/quote] Hey Weedy, Can you explain how you hooked a function to work post-controller? I am reading about hooks in the user-guide but it is a little confusing. Thanks a bunch in advance
[eluser]weedy[/eluser]
Yeah, what I did was made the hook a function (It could've been a class but since I can't have 2 controllers, it would be useless anyway): Code: <? This is loaded post controller: Code: $hook['post_controller'][] = array( Uses user_model: Code: <? And supplemented by User class: Code: <?php Hope that helps. |
Welcome Guest, Not a member yet? Register Sign In |