Written by James McDonald

September 24, 2014

By default CakePHP uses the session timeout value in php.ini

But sometimes you might want to specify a very short Session timeout for testing your code

To do that you open Config/core.php and add a value to the “Session” Configure::write area

Configure::write('Session', array(
		'defaults' => 'php',
                'timeout' => 1 // 1 minute for testing

The reason I needed to shorten my timeout was that I was creating jquery mobile page that did an ajax request to update itself and when the session had expired I needed to test the error: block of the ajax request. I was using the CakePHP ajax Js Helper

I’ve recently removed all references to the JsHelper from my CakePHP application for a number of reasons:

  1. As far as someone on the cakephp IRC channel it’s not going to be a part of Cake 3
  2. When you use the link method and you have about 160 links on a page you get 160 $.ajax({}) blocks embedded in your page
  3. When you try and say cache that code to disk cake didn’t seem to delete the temporary files so  you had a growing number of used once files in webroot/js (which had to be writeable to allow the files to be generated)
  4. You can write plain jquery 1 or 2 blocks of plain jquery to replace the autogenerated code and it’s a lot smaller and simple


// this creates a <a href=""> link
// and performs an ajax call as it's 
// action

echo $this->Js->link( 
        $map['territory_number'], // This is the link text
        array( // this is the url it submits to
               'controller' => 'maps',
               'action' => 'view_details',
               'method' => 'GET', // use GET which is the default
               'update' => "#" . 'container-' . $key  , // element on page to update with the content from the reply
               'before' =>  '$.mobile.loading("show");',
               'success' => '$.mobile.loading("hide");',
               'error' => '$.mobile.loading("hide"); $("#error-pop-error").html(errorThrown); $("#error-pop").popup(); $("#error-pop").popup("open");',
               //'confirm' => 'Y\'all really want to do this?',
               'class' => 'my-btn ' . $class


Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…

Meraki Open Source Licenses

Until today I assumed that Meraki was built in-house with only closed source software. But having a look at the...


If you have Veeam backup failing with the Updating BCD failed with Cannot update SafeBoot flag and SentinelOne is...