Welcome Guest, Not a member yet? Register   Sign In
Config overriding changes made from Hook
#1

[eluser]Unknown[/eluser]
Hi all,

I have a post_controller_constructor hook that is changing some configuration variables (and is doing so successfully). On each page load, the hook checks to see if the base_url variable matches with a variable I am defining somewhere else. The config->set call works properly, and while I am on that page, the config variable is correct. However, once I load a different page, the config variables have been changed back to their default, and the hook must reset them once again.

The issue here is that I am using the base_url to determine which database to use (I have multiple sites hitting one codebase), and I would like to destroy the session if a user tries to switch which site they are on. Since the config is overriding my hook's changes, my app keeps thinking that the user either just entered that site and needs to login, or attempted to switch to a different site, and needs to have their session destroyed.

Here is some code sampling the issue I am encountering (I currently have the session destroy disabled, becaue it is destroying my session on every single page):

Code:
// post_controller_constructor hook
function configURLReplace ( $site_instance name )
    {
        if ( empty ( $site_instance name ) )
        {
            die ( 'Invalid URL' );
        }

        $this->CI =& get_instance();

        /* set the base url and the site file root url */
        // if root url is empty, everything needs to be initialized
        $root_site_url = $this->CI->config->item ( 'root_site_url' ) ;

// this occurs every time -- which makes me thing config is overriding my hook's config changes
        if ( empty ( $root_site_url ) )
        {

            // destroy the session -- so you can't jump from site to site
            // without having to login...
            //$this->CI->load->library ( 'session' );
            //$this->CI->session->sess_destroy();

            // get the base_url
            $base_url = $this->CI->config->item ( 'base_url' ) ;

            // init the root url (used for files, images, etc)
            $this->CI->config->set_item ( 'root_site_url' , $base_url ) ;

            // and set the base url to include the site instance name
            $this->CI->config->set_item ( 'base_url' , $base_url . $site_instance_name . '/' ) ;
        }

    }

Please let me know if you can give me a shove in the right direction Smile




Theme © iAndrew 2016 - Forum software by © MyBB