Welcome Guest, Not a member yet? Register   Sign In
Calling Session-Library from post_system-hook!
#1

[eluser]taig[/eluser]
Hi all,

I've written my own Session-Class (replaced the existing one - didn't extend). During the program flow there are several set_userdata()-functions executed (just like the original CI_Session-Class). Later on my post_system-hook is supposed to launch the method transmit_data() bundling all updates into one query.

The first issue I came across is that I'm not able to use the hook like this:
Code:
$hook['post_system'] = array(
                         'class'    => 'Session',
                         'function' => 'transmit_data',
                         'filename' => 'Session.php',
                         'filepath' => 'libraries'
                         );
It's telling me that he can't redeclare class CI_Session. Alright so I guess that's how the CI-hooks work: Create a new instance of the class and then launch the method.

So I changed my approach calling a procedural function:
Code:
$hook['post_system'] = array(
                         'class'    => '',
                         'function' => 'transmit_data_hook',
                         'filename' => 'Session.php',
                         'filepath' => 'hooks'
                         );
Code:
function transmit_data_hook()
{
    $CI = &get;_instance(); // That strange semicolon seems to be a bug in the forum-software

    $CI->session->transmit_data();
}
But now I've got a new problem, and I can't quite figure out why:
Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined property: Gate::$session

Filename: hooks/Session.php

Line Number: 14

Fatal error: Call to a member function transmit_data() on a non-object in /[...]/application/hooks/Session.php on line 14
So I took a look inside the $CI-variable in my hook finding these class-instances available:
Code:
config
log
utf8
uri
router
output
security
input
lang
load
db
url
user_agent
encrypt
session_handling
usertracking
I'm autoloading the Session-Class running my session-routine without any problems. But why is the library already gone in post_controller-hook? Did the Codeigniter-core already automatically destroyed it at this point? I can't figure it out ): I appreciate any hints from people who know better about Codeigniters mechanisms!

Thanks for looking into my problem in advance!

Best regards
_taig
#2

[eluser]toopay[/eluser]
[quote author="taig" date="1305492471"]...Later on my post_system-hook [/quote]

[quote author="taig" date="1305492471"]...But why is the library already gone in post_controller-hook[/quote]

Which one you used? post_system or post_controller ? Because post_system hook is called after the final rendered page is sent to the browser, at the end of system execution after the finalized data is sent to the browser.
#3

[eluser]taig[/eluser]
Hey toopay,

thanks for your reply and sorry for my inconsistency. Actually I've been using the post_system-hook but after reading your message I also tried the post_controller-hook. Unfortunately I'm having the same issue, but I realized it only fails on redirects()!!

My redirect-function looks like this:
Code:
function redirect($uri = '', $method = 'location', $http_response_code = 302)
    {
        // Custom change to run hooks before redirect!
        $CI = &get;_instance();

        $CI->hooks->_call_hook('post_controller');
        $CI->hooks->_call_hook('display_override');
        $CI->hooks->_call_hook('post_system');

        if ( ! preg_match('#^https?://#i', $uri))
        {
            $uri = site_url($uri);
        }

        switch($method)
        {
            case 'refresh'    : header("Refresh:0;url=".$uri);
                break;
            default            : header("Location: ".$uri, TRUE, $http_response_code);
                break;
        }
        exit;
    }
Anyway, this insight doesn't really help me to get rid of my confusion because I didn't run into any trouble with my modified version of the redirect()-function so far. I just don't get it why my session-class is already gone at post-controller/-system. If I should provide any more of my code just let me know, because I'm not quite sure where to start searching for the root of my issue |}-:
#4

[eluser]toopay[/eluser]
[quote author="taig" date="1305492471"]I've written my own Session-Class (replaced the existing one - didn't extend). [/quote]

Why you need or what you want to achieve, which drive you to write a new ones instead extending the original session class? This will make other easier to help you ;-)
#5

[eluser]taig[/eluser]
[quote author="toopay" date="1305649938"]Why you need or what you want to achieve, which drive you to write a new ones instead extending the original session class? This will make other easier to help you ;-)[/quote]

Hey,

there are mainly three reasons why I didn't like the native session-implementation.

I didn't want to store all my userdata in a json-string making it impossible to do JOINs on some stuff like the location of the user (and plenty more fields).

Also I didn't like the way the set_userdata()-function worked performing a query on each call. I use this function quite a lot and prefer bundling it into one query or even leave it out if it's not necessary anymore (Creating a notification, displaying it and removing it from query-queue in one run).

I wanted to try writing a session-class that can handle users without cookies too.

All in all it's working pretty well even though I completely changed the way the session-class works. The API stayed nearly the same. Just ran into these troubles I described above. But I guess it's too difficult to understand what's going wrong here without being involved into the system. I just wanted to give it a try hoping someone else already experienced something similar. But I guess I'm out of luck this time.




Theme © iAndrew 2016 - Forum software by © MyBB