Archives for: June 2012
CakePHP 2: accessing the Request object from anywhere

If you’re working in a place other than a controller, view, helper, or component – such as an event listener, custom lib class, etc. – and need to access the CakeRequest object (which is available as $this->request in controllers/views/helpers), then use Router to get it: $request = Router::getRequest();

By Jamie with 0 comments
Using path conditions with Hash::extract() in CakePHP 2

The CakePHP book page on the new Hash class, the replacement for Set, is not exactly extensive. There’s even an error: the arguments for Hash::extract are $data, $path, but the example given uses $path, $data (the former is correct). One aspect of Hash that the book is particularly quiet on is how to use path conditions with methods such as [...]

By Jamie with 1 comment