Blog

CakePHP

Last week the first alpha release of CakePHP 4.0 was made available for testing. This means that the next major version of CakePHP is getting nearer. This is a good opportunity to look ahead at the new and changing functionality of the next version of this PHP framework.

I’ve recently noticed a number of people trying to use CakePHP 2’s updateAll() method very badly.

Let’s first get one thing straight: updateAll() is not the intended way of updating a record in CakePHP, use save() for that!

The last couple of days I’ve been developing a little app that imports Twitter feeds and saves tweets to a MySQL database; however, I quickly hit an issue where certain tweets would not save. MySQL was returning the error message ‘SQLSTATE[HY000]: General error: 1366 Incorrect string value’. Looking at the specific tweets causing the database to throw the error I noticed that they contained emoticons.

This is a kind of follow-up to my recent article on Essential Sublime Text 3 Plugins for PHP Developers to explain how to install and configure Sublime-phpcs for the CakePHP code standard. Although I’m describing how to configure phpcs specifically for Cake it will hopefully be of use to anyone wanting to get started with phpcs in Sublime Text and start developing better code.

The first stable release of CakePHP 3 came out earlier this week so I’ve started the process of updating my Cake plugins. The first one to be updated is VideoEmbed (on the basis that it seems to be the most popular).

Diagram of CakePHP's observer pattern
CakePHP's Observer Pattern (the Events System)

It seems that Events are an often ignored feature of the CakePHP framework. Introduced in version 2.1 the events system provides a means of applying logic that generally doesn’t belong in a model or controller. Developing in Cake is all about its fat models and skinny controllers, but there are some things that belong in neither, and shouldn’t really be placed in a model just to make it fatter!