Welcome Guest, Not a member yet? Register   Sign In
how to: conditonal config


I want to be able to change the cache dir depending whether or not a suer is logged in.

I'm trying to do this from within the head.php view and have tried a bunch of methods including:

 $CI =& get_instance(); 
 if ($cust > 0) { 
 $config['cache_path'] = '/location/to/my/install/application/cache2';

What is the correct syntax please?

Thanks a lot.

i think the best way to achieve what you want is a hook - below an example

in your application/config/hooks.php

PHP Code:
$hook['pre_controller'][] = array(
"class" => "AppConfigCustomization",
"function" => "initialize",
"filename" => "AppConfigCustomization.php",
"filepath" => "hooks"

in your application/hooks/ folder put a file named AppConfigCustomization.php

PHP Code:
class AppConfigCustomization


    public function 
$this->ci = &get_instance();
    public function 
        if (

something like this is clean and should work

Thanks a lot, I'll give this a go and let you know.

Bugger. didn't work.  Tried a few variations on this,  and it just wont overwrite the default cache path.

As long as you don't reload the config file after you do this, the following should work:

PHP Code:


(This post was last modified: 11-23-2015, 08:37 PM by starchild.)

*sigh* this is hurting my head.

I'm able to set cache path, but the problem now is that the session seems to be cached itself!
As soon as user logs in and caches the page to the assigned dir, even if I log out again, I'm still getting the logged in cache files being returned.


PHP Code:
$cust_id $this->session->userdata('cust_id');
        if (!isset(
$cust_id) || $cust_id <=) {
$this->config->set_item("cache_path","/path/to/application/cache3/") ;
        } else {

I guess the solution lies in environments, but how to assign an environment based on session data?  It all seems to be like a chicken and egg situation.

Theme © iAndrew 2016 - Forum software by © MyBB