Category: CakePHP
CakeSWXPHP and PHP 5.3
Small issue when using CakeSWXPHP and PHP 5.3 – in app/vendors/swx/php/core/shared/util/MedthodTable.php there are a few eregireplace() calls that need to be changed to pregreplace().
CakePHP, MAMP, and MySQL
Diving back into CakePHP I was trying to bake a model for my project. The command kept kicking back, and I remembered that the database config for MAMP CakePHP installs required a port entry. So:
- var $default = array(
- 'driver' => 'mysql',
- 'persistent' => false,
- 'host' => 'localhost',
- 'login' => 'root',
- 'password' => 'root',
- 'database' => 'mydbname',
- 'prefix' => '',
- 'port' => '/Applications/MAMP/tmp/mysql/mysql.sock'
- );
That last 'port' line was the key.
CakePHP and Model File Names
Another example of the little things that you learn when picking up a new framework: filenames for your CakePHP Models should be lowercase. For example, section.php and not Section.php.
I'd been working on a small CMS for a friend's site, and even though everything worked perfectly on my local MAMP install, when I uploaded it to the production webserver for testing I kept getting an error when retrieving items that had an association with another model:
Notice (8): Undefined index: Section
In this case I had a Section Model that had an association with many Items. Section hasMany Items, in other words. When retrieving the Items listing the respective Sections could not be retrieved.
After I renamed my model files to lowercase and flushed the /app/tmp cache the associations were recognized, and the listing of Items showed the relationship to the associated Section objects.
I think this happened because I hand-coded a few of the Model files before switching to bake to scaffold things.
Oh, and a final note to self: the AMF/SWX CakeSWXPHP plugin appears to require PHP 5. Couldn't understand why the AMF calls were failing until I checked the PHP version on the remote production server. Sure enough, it was still running PHP 4.