CakePHP and Redis

I recently had to upscale a client’s CakePHP application across multiple front-end web servers on AWS. CakePHP’s file system cache and session storage doesn’t cut it any more. I needed a way of sharing sessions and cached objects. Step in Redis. A centralised, in-memory database, much like memcache – but nicer!

Continue reading “CakePHP and Redis”

[Snippet] Get last SQL query in CakePHP Controller

Sometimes, whilst debugging, it is useful to see the last SQL query that CakePHP executed. This is easy if you are in the view, however not so easy in the Model or Controller.
Here’s how I over came the issue.

$log = $this-&gt;TheModelName-&gt;getDataSource()-&gt;getLog(false, false); debug($log);
<span style="line-height: 1.5em;">

CakePHP: A cheeky way of using a helper in a controller

In CakePHP sometimes you need to use a helper, such as the HtmlHelper in a controller. For example I needed to build links in a HTML email within a controller only (no view) action


class SomeController extends AppController {
    function index() {
        $view = new View($this);
        $Html = $view-&gt;loadHelper('Html');
        debug($html-&gt;link('I Am Kieran', ''));