Cron Dispatcher CakePHP 2.0

In case anyone else is interested, In the new CakePHP 2.0.5, you will an index.php in webroot folder: Copy this file and name it cron_dispatcher.php, and place it into the same directory (webroot) You will find this code at the very bottom: $Dispatcher = new Dispatcher(); $Dispatcher->dispatch(new CakeRequest(), new CakeResponse(array(‘charset’ => Configure::read(‘App.encoding’)))); change the bottom … Read more

How to Install DebugKit on CakePHP

How to Install DebugKit for CakePHP (in just 4 easy steps!): STEP 1 (option A): The traditional / download method: Create a DebugKit folder within your app/Plugin directory, and put the contents of the download into it (not the top-level folder – the stuff within it). If you know how to clone from github, that … Read more

What is the equivalent to getLastInsertId() in Cakephp?

CakePHP has two methods for getting the last inserted id: Model::getLastInsertID() and Model::getInsertID(). Actually these methods are identical so it really doesn’t matter which method you use. echo $this->ModelName->getInsertID(); echo $this->ModelName->getLastInsertID(); This methods can be found in cake/libs/model/model.php on line 2768

Regular expression for GB based and only numeric phone number

There are some UK phone number regular expressions here. The most highly rated one from that page is: ^(((\+44\s?\d{4}|\(?0\d{4}\)?)\s?\d{3}\s?\d{3})|((\+44\s?\d{3}|\(?0\d{3}\)?)\s?\d{3}\s?\d{4})|((\+44\s?\d{2}|\(?0\d{2}\)?)\s?\d{4}\s?\d{4}))(\s?\#(\d{4}|\d{3}))?$ It is described as: Matches +447222555555 | +44 7222 555 555 | (0722) 5555555 #2222 Non-Matches (+447222)555555 | +44(7222)555555 | (0722) 5555555 #22 Personally I would not put a strict regex on a phone number unless … Read more

Undefined variable: $_SESSION

You need make sure to start the session at the top of every PHP file where you want to use the $_SESSION superglobal. Like this: <?php session_start(); echo $_SESSION[‘youritem’]; ?> You forgot the Session HELPER. Check this link : book.cakephp.org/2.0/en/core-libraries/helpers/session.html

How to output serialized JSON view data as an array of objects, instead of wrapped in an outer object?

Set a string for the _serialize option instead of an array. An array indicates that there might be multiple view vars that need to be serialized, and that requires them to be packed into separate object properties. $this->set(array( ‘platformusers’ => $platformusers, ‘_serialize’ => ‘platformusers’ )); That should give you the desired result.