Lately, I’ve been taking some serious time out of my schedule to sit down and really examine a few of the top PHP Web frameworks (CakePHP, Symfony, & Zend) even more than I had previously. After a bunch of reading, tinkering, and playing around, I can now officially declare: “I think CakePHP is the best”. There I said it, I hope I won’t regret it… heh.
In fact, after actually sitting down and expanding on the basic blog tutorial offered in the manual, I am tepidly excited about the prospects of implementing something cool and truly useful in Cake (I may even switch The Weber Report over to my new, fancy, Cake-Powered, conglomeration that I created during the learning process) and really start taking advantage of the MVC Design Pattern.
Now that I have read through the manual a few times, I can humbly offer some of my favorite parts of the Cake experience:
Powerful Associations Between Models
“One of the most powerful features of CakePHP is the relational
mapping provided by the model. In CakePHP, the links between tables are
handled through associations. Associations are the glue between related
There are four types of associations in CakePHP:
When associations between models have been defined, Cake will
automagically fetch models related to the model you are working with.
For example, if a Post model is related to an Author model using a
hasMany association, making a call to $this->Post->findAll() in a
controller will fetch Post records, as well as all the Author records
they are related to.”
Powerfully Flexible Data Validation Features
“Validations are defined using Perl-compatibile regular expressions,
some of which are pre-defined in /libs/validators.php. These are:
But custom validation (outside of regular expressions) is also extremely easy. If you’d like to perform some custom validation apart from the
regex based Cake validation, you can use the invalidate() function of
your model to flag a field as erroneous. Imagine that you wanted to show
an error on a form when a user tries to create a username that already
exists in the system. Because you can’t just ask Cake to find that out
using regex, you’ll need to do your own validation, and flag the field
as invalid to invoke Cake’s normal form invalidation process.”
Stringent Security Component
“The Security component is used to secure your controller actions
against malicious or errant requests. It allows you to set up the
conditions under which an action can be requested, and optionally
specify how to deal with requests that don’t meet those requirements.
So if a request doesn’t meet the security requirements that we
define, what happens to it? By default, the request is black-holed,
which means that the client is sent a 404 header, and the application
immediately exits. However, the Security component has a
$blackHoleCallback property, which you can set to the name of a custom
callback function defined in your controller. Rather than simply give a 404 header and then nothing, this
property allows you to perform some additional checking on the request,
redirect the request to another location, or even log the IP address of
the offending client.
Every time the Security component is loaded, even if it is not
being used to protect an action, it does the following things: First, it
generates an authentication key using the core Security class. Then, it
writes this key to the session, along with an expiration date and some
additional information (the expiration date is determined by your configuration file).
Next, it sets the key in your controller, to be referenced later.
Then in your view files, any form tag you generate using
$html->formTag() will also contain a hidden input field with the
authentication key. That way, when the form is POSTed, the Security
component can compare that value to the value in the session on the
receiving end of the request. After that, the authentication key is
regenerated, and the session is updated for the next request.”
Cool Scaffolding (Similar to Rails)
“So cool that you’ll want to use it in production apps. Now, we
think its cool, too, but please realize that scaffolding is… well…
just scaffolding. It’s a bunch of stuff you throw up real quick during
the beginning of a project in order to get started. It isn’t meant to be
completely flexible. So, if you find yourself really wanting to
customize your logic and your views, its time to pull your scaffolding
down in order to write some code.
Scaffolding is a great way of getting the early parts of
developing a web application started. Early database schemas are
volatile and subject to change, which is perfectly normal in the early
part of the design process. This has a downside: a web developer hates
creating forms that never will see real use. To reduce the strain on the
developer, scaffolding has been included in Cake. Scaffolding analyzes
your database tables and creates standard lists with add, delete and
edit buttons, standard forms for editing and standard views for
inspecting a single item in the database.”
Remember, these are just some of the highlights. There is a LOT more in the manual to get you excited. In the near future, I’d really like to contribute a bit to the Bakery and really begin discovering the power of Cake in ways I can’t yet foresee.
You know you want to check Cake out, so stop wasting time… take the leap!