Welcome Guest, Not a member yet? Register   Sign In
Telling the session class to go to sleep
#1

[eluser]a.somervell[/eluser]
Its been a while since I was a regular here! Just launched this site: http://www.biggie.co.nz completely written in Codeigniter. It has a forum with over 3.5m posts in it, again... powered by CI Smile

SO anyway... i'm serving CSS and JS off the application server, big long expires headers on them, gzipped etc. but it looks like i'm setting and re-setting the user's cookie for every request...

So how do you reckon I forget the session stuff for a single controller? (In this case I have a controller called "common" that does all this)
#2

[eluser]a.somervell[/eluser]
Buuump
#3

[eluser]helmutbjorg[/eluser]
You might need to be bit clearer in what you are asking... cookies, session, css, js, controller? How about an example?
#4

[eluser]a.somervell[/eluser]
Hrm... ok.

When you request http://www.biggie.co.nz/common/css/v4_base.css it is a controller called "common", funciton css. I have the same for js so I can build the files dynamically.

Code:
function css($object) {
    $this->output->set_header("Content-type: text/css");
    $this->output->set_header("Cache-Control: public, max-age=".$this->config->item('cache'));
    $this->load->view('/common/css/'.$object);
}

But that controller fires up the usual codeigniter session stuff, which reads/sets a cookie and hits the sessions table of the DB.

In short, i'd like them not to call the session library, without splitting it out of my main app, and without taking session out of my autoload config.
#5

[eluser]helmutbjorg[/eluser]
Does the common controller extend the default controller or have you made a custom one that you extend from?

For example
Code:
class Common extends Controller { }
or
Code:
class Common extends MY_Controller { }
or
Code:
class Common extends Completely_different_controller { }
#6

[eluser]a.somervell[/eluser]
Code:
class Common extends Controller {
#7

[eluser]helmutbjorg[/eluser]
You probably can't do it without removing the session from the autoload config... You could create a custom controller like so that you use for all your other pages.

Code:
// application/libraries/MY_Controller.php
class MY_Controller extends Controller {

    function MY_Controller {
        parent::Controller();
        $this->load->library('session');
        // More crap here if you want...
    }

}

// Then in your other controllers you extend this one
class Other extends MY_Controller {

    function Other() {
        parent::MY_Controller();
        // Now your session is available here...
    }

}


// And in your common one you skip the MY_Controller extend directly from default
class Common extends Controller {

    function Common() {
        parent::Controller();
        // No session!
    }

}
#8

[eluser]a.somervell[/eluser]
*nods* Thanks mate thats probably the answer... i'll begrudgingly give up my auto-load Tongue
#9

[eluser]CtheB[/eluser]
You really shouldn't autoload the session class (because the CI session class is very very slow)
And you really shouldn't handle the dynamic css like this (because that is also very slow, and you need to generate your css file every time again (ouch!) no caching possible :-S )

2 options:

1. You can route your application to 1 main controller wich handles the dynamic css in method x
2. You can extend controller.php with MY_Controller.php and here handle the dynamic css in method x.

With one of the two options make a new method wich does the following:

1. Look for the last update time of a dynamically generated combined css file.
2. Look for the last update time of all the included css files.
3. If at least 1 css file has a later update time then the combined file -> Generate the combined css file again.
4. In your <head> section of your template you can point to the combined file (wich you name something like styles_v16.css.php or whatever you like)

Some tips:

# If you generate the css file, include some headers, so PHP knows the file is a CSS file and set the expire date etc.
# You can make different versions of your combined css file like 1_2_3_4_5_8_11_14.css.php and 1_2_3_7_9_12_13.css.php
so you only need to include the css inside the file, what is needed for the current page.
# You can make a database table with all the css files or load them in an array inside your controllers so you can handle them afterwards in your main controller.
# Same situation is for all your JS files: combine them in 1 file dynamically!
# Good luck!
#10

[eluser]a.somervell[/eluser]
Thanks CtheB

I am using CI caching and far futures expires headers for all, and we have a base css for the site and different ones for the different sections / subsections so we're all good there Smile

Going to do the MY_controller thing now *gulp*




Theme © iAndrew 2016 - Forum software by © MyBB