Feb 09

cakephp.gifLately, 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
logical units.

There are four types of associations in CakePHP:

- hasOne
- hasMany
- belongsTo
- hasAndBelongsToMany

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!

16 Responses to “CakePHP: Is It Truly The Best PHP Web Framework?”

  1. Anonymous Says:

    Glad to see you're getting on the MVC bandwagon. I won't give you quite as much grief for passing on Ruby now.

  2. Dustin Weber Says:

    Yeah, I’m down with it. I’ve known it’s power ever since I started tinkering with Rails, but hadn’t truly applied it in the PHP arena.
    I think it’ll work out swell.
    I haven’t passed on Ruby either, just isn’t a viable option for my work setting right now.
    Outside projects are game-on though! So hah!
    - Dustin

  3. Anonymous Says:

    The scaffolding can come in so handy. It is the best part of whole thing. I use it often,.

  4. Dustin Weber Says:

    Taking advantage of the scaffolding is definitely a hugely powerful aspect of Cake (and other MVC frameworks that offer scaffolding). It can really save some time and effort in the pre-beta stage.
    - Dustin Weber

  5. Mark Crane Says:

    CakePHP looked interesting until I found it didn’t yet support PDO (PHP data objects). If CakePHP is the most popular framework that scares me a bit since it is a slow on supporting PHP 5 features ie PDO that has been available for approximately 2 years. Without PDO the database options are pretty limited in CakePHP. Until PDO is supported in CakePHP I will pass.

  6. kuman Says:

    I tried my hands on CakePHP once (about half-year ago) when I was evaluating a few frameworks for my project. I didn’t appeal to me coz it seems awkward to have to define the data relationships. I wish it had some kind of tool to read from the database and generate the model classes. Defining the relationships by hand is ok at the start of the project but what happens when you wanted to make changes to them (I know some would say you can use the scaffolding features before really committing/translating the relationships to the db schema but imagine if you’ve done all that and at some point decided to commit to the database and a few months later have to modify the relationships, will the changes be easy to make?). This is one of the reasons that I had to choose Symfony over CakePHP. Don’t get me wrong though, that was the only reason I decided not to go with CakePHP. I liked it’s every other feature.

  7. AceMacaro Says:

    Never known any framework, my code in php are disgusting. I have to write all the codes at the upper section of my .php.
    I been learning cakePHP for a week now, and at first its kinda frustrating,
    for lack of documents, newbie examples and the list of functions available. (Thanks to donutczar for his helpers example, it helps a lot).
    Anyway, it is hard(after a week of reading), but now i currently developing a web payroll system, yup, “RAPID DEVELOPMENT” is the right term. but still it slows me down, cause i need to read(manual) or ask question(forums and #cakephp) once in a while. Cakephp helps me alot. The team says “it was easy”, some says “it was hard”. I trust the team and continue learning.

  8. derek Says:

    Symfony works PHP5’s PDO class library and this in not supported at cakePHP since cake supports PHP 4 as well.. :(

  9. Salman Says:

    I am reviewing many frameworks and PHPCake seems to be a nice one.

  10. Remo Harsono Says:

    Probably the worst part of CakePHP is its documentation for new CakePHP users. I think CakePHP Documentation Team should learn from what PHP Documentation Team has done to new PHP users. I think PHP has grown so fast was not only because of its easy to learn scripting language but also very very good documentation especially for new users (like me).

  11. Jim Says:

    Cake falls short on the “intuitiveness” part of a framework – you have to go to the docs for everything, since there doesn’t seem to be much of coherence to the syntax or the structure. Additionally, the routing model leaves a lot to be desired, and CakePHP templates look like the ugly inline PHP we’re trying to avoid in the first place.

    If you are serious about finding a framework that’s actually going to decrease your development time, even in the beginning, it’s time to look at the Fuse PHP Framework. Built to have a low barrier to entry while maintaining the features you actually need (user authentication, simple but extremely robust templates, easy data access, etc), it’s the only PHP framework you’re going to need. Here are some reasons why:


  12. Dave K Says:

    I just moved companies and the new joint is all PHP, I came from a place which evaluated a bunch of technologies and eventually settled on Django and now I’m spending time evaluating PHP’s various frameworks and I’ve got to say, compared to how easy Django is most of the PHP frameworks seem very immature and incomplete.

  13. Jeremy Says:

    I don’t understand combining both php 5.0 and php 4.0 compatibility for any one framework. Couldn’t they split into two parallel frameworks or even 2 separate projects? One for 4.0+ and one for 5.0+ (or 5.2+)? That way the 5.0 /5.2 version could support PDO and 4.0+ version would just use the older data connection methods. This could keep the size and complexity down among many other improvements.

  14. pawan sharma Says:

    hello friends,

    I love Cakephp.

    i want the best e-book of CAKEPHP e-book with project practice.
    if you have please send me. My email is pawansharma13@gmail.com.


  15. benny l.e.p Says:

    cakephp it’s easy , i agree it’s lack of documentation but if you dig further, you will never look in to another framework, if you need advance documentation you should look in http://api.cakephp.org :)

  16. octavio Says:

    The way cake create relation in the model is stolen from the on rails filosofy, whcih for me is better. I think Symfony is a good one.

Leave a Reply