Two months ago I wrote about benefits of Community Frameworks compared with Home-Grown ones. In the article I mentioned some of the benefits of Cake, but it was “scratching the surface” rather than complete info
Challengers I Told Ya ShirtChallengers I Told Ya Shirt
10 reasons to choose CakePHP as Framework
1. 10 reasons to choose CakePHP as Framework
Two months ago I wrote about benefits of Community Frameworks compared with Home-
Grown ones. In the article I mentioned some of the benefits of Cake, but it was “scratching
the surface” rather than complete info.
Here I want to list all those things, but near to each of them I will give short explanation
what is it and how CakePHP implement it.
So, if somebody ask me what are those 10 things which drive me to choose this
framework as my primary one I will answer with:
MVC Pattern – Model support data handling, with model class you can insert, update,
delete or read the data from the database. View support data rendering on the
screen. Controller process and responds to events and can modify data before it interact
with the model (database). With this pattern it’s very easy to separate the logic from the
presentation, which is very useful for large applications and sites. How is in CakePHP? It is
MVC Driven framework, so you cannot do much if you don’t use this pattern. I found it
really handy once you start thinking MVC way.
2. ORM – Object Relational Mapping is a programming technique for converting data
between incompatible type systems in databases and object-oriented programming
languages /scarry huh?/. With simple words this mean, that every table is represented
from a class. In these classes you can define relations between other tables, validation
definition and also you can predefine specific callbacks especially for that table. The most
important thing for me is the relation definitions, because once they are properly defined
you can have sub records /from the related tables/ without doing anything specific – you
just have them when you get the main record. This one I find as extremely helpful. I had
some projects in which I didn’t wrote a single line of SQL.
3. Proper class inheritance – Cake has two main folders in each project. First one is
the core lib /cake/, where I prefer only to watch, but not to touch /just like peep show/.
The second folder is the Application specific one /app/. These days I read an
article “inheritance is evil” and the author is probably partly right, but in CakePHP
inheritance is very sensible and understandable. All Application specific controllers extend
AppController class which is empty, but can be extended with some extra logic or there you
can predefine some core functions which you want in specific way. The same apply to
Models which extends AppModel where you can predefine for example deletion instead to
delete a record to mark it only as deleted with a flag etc. With these two classes you can
change almost everything you want.
Easily extend with Components,Helpers,Behaviours and Plug-ins – This
point is very important for me, because it allow us to create parts of reusable code which is
very helpful for more than one project. Rather than extend Cake’s core libraries, special
functionality can be placed in components, helpers, behaviours and a combination of
Models, Views and Controllers encapsulated as Plug-ins – this way you can modularize your
projects.
There are a lot of plug-ins helpers and components in CakeForge site, so you don’t need to
write everything from the scratch.
4. Zero configuration – In CakePHP there isn’t single part of code /configuration/ where
you need to specify the location of the library or the url of the site – everything is auto-
detect and the only thing you need to care about is the Database connection settings.
Build in validation – When I start coding with Cake the validation was really basic /at
least that’s what I saw in the tutorials and articles/, but now it become really useful feature
where you could attach multiple advanced validation rules to single field. I have some ideas
for Ajax validation which I would share in a new article later on.
5. Ajax support – There is Ajax helper class in the core lib which you could use in
variousways – form submit through Ajax, Event observer or build in Autocomplete. I have
an article about Autocomplete with ID=>Value relation which you can take a look. CakePHP
uses Ajax with Prototype and Scriptaculous.
6. ACL Functionality and Security – CakePHP has build in Authorization and Security.
There are many articles explaining the ACL logic, the one in the Cake Manual is very useful.
CRUDscaffolding – CRUD come from Create, Read, Update, Delete – these are the main
activities in most of web applications. It is extremely helpful, because with one single line of
code you can see preliminary view of your application. In cake core lib there was bake.php,
now becoming /console/cake. With this script is very easy to be “produced” all models,
controllers and views and after that they could be modified for the specific requirements of
the application. I really like that feature and I am using it every time when I start new
application – saves a lot of time.
Ability to create tests – This so far is not my favourite feature, but I would really
want to use it in the future. Cake provide ability to create tests which will help you to check
the critical points in your applications. There are core tests, as well as custom ones, which
7. you can build your own. It’s handy when you build a large application where some parts
are critical and the performance should be checked carefully.