CodeIgniter Forums

Full Version: Using Hook Points
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]jitterbug[/eluser]
Can anyone explain the use of the post-controller-constructor hookpoint? The wiki page says

Called immediately after your controller is instantiated, but prior to any method calls happening.

Would imply that the hook is called after autoload libraries and classes have been loaded. However if you read the print_r($this) in the hook's function youll see that the autoload classes have been declared but hold no data.

It seems like the hooks are hooking to early, because this information is instantiated if you call print_r($this) in the default controller's constructor, and in the hook if the hook is a post-controller hook.

Code:
[load] => CI_Loader Object
        (
            [_ci_ob_level] => 1
            [_ci_view_path] => C:\wamp\www/system/application/views/
            [_ci_is_php5] => 1
            [_ci_is_instance] =>
            [_ci_cached_vars] => Array
                (
                )

            [_ci_classes] => Array
                (
                    [session] => session
                )

            [_ci_loaded_files] => Array
                (
                    [0] => C:\wamp\www/system/libraries/Session.php
                )

            [_ci_models] => Array
                (
                    [0] => userauth
                )

            [_ci_helpers] => Array
                (
                    [string_helper] => 1
                    [url_helper] => 1
                    [form_helper] => 1
                )

            [_ci_plugins] => Array
                (
                )

            [_ci_varmap] => Array
                (
                    [unit_test] => unit
                    [user_agent] => agent
                )

        )

NOTE: If you try to load the session in the post-controller-constructor hook you will get an error b/c the models are not loaded.
Cliffs: Is the post-controller-constructor hook working properly?

El Forum

[eluser]jitterbug[/eluser]
I also found that if you use a hook as a post-controller-constructor and a post-controller (different functions are called at each hook point) using a single hook controller class that the session information available is determined by the more restrictive hook point. In this case being the post-controller-constructor.