It is almost a year ago when I started seeing her, and ever since I am in love with her. From then on, I have been with her in quite a few projects, and she has never let me down. Its true that at times the relationship has not gone that well, but its mostly my fault. Either it was my lack of understanding her well or my impatience, or just the pressure of tight deadlines, that I ended up in uncomfortable situations with her. But she never let me down. Eventually, we made it through, and here I am one year later, writing about my beautiful relationship with Cakephp.
Oh hell! I didnt expect to get carried away this early, but contrary to what you are thinking, this article is not about my romance with CakePHP, but again, you never know when I start to get carried away
For what little I have used this wonderful framework, it has been solely 1.1. Mostly due to lack of time, I never actually tried the new CakePHP 1.2. This is my attempt to get myself in tune with the latest release of CakePHP, and continue the romance. In my attempt to learn more about 1.2 (without getting into the code right away), I figured out that there is still no good documentation available. And whatever there is, are scattered across the web. Here I try to get them all together, and I hope this will help others to find 1.2 resources easily, and eventually help them adopt 1.2 faster.
Features
Behaviours, With Association, enhanced validation, a new helper for form, built in pagination support, integrated unit testing and caching are some of the new features to name. But, if you are looking for a more clearer idea about what are the new features in 1.2, head right to the article by cakebaker called What’s new in CakePHP 1.2 ? The article clearly lists down all the major changes made in 1.2. Cakebaker also has an article that compares 1.1 and 1.2: Which Cake should you eat?. This will help you make your choice, but in my humble opinion, I still think 1.2 will be difficult for most people to start with, if they are new to CakePHP. The major reason being the lack of proper documentation. Having said that, most of 1.1 documentation will still work for 1.2, but there is the danger of using any deprecated feature or not taking full advantage of 1.2. If you are the type who likes the feeling of going into the unknown, then dive straight in 1.2. On the other hand, if you like to play it safe, and want complete control over what you are doing, you should go for 1.1. But again, my judgement might be totally wrong :p. Another reason, why you should start with 1.1 is that it will allow you to be in a better situation to comprehend the cool features that 1.2 comes with.
Ok! Enough of my opinions, now lets continue with the rest of 1.2 resources. The next one is by Nate: Bag o’ Tricks. This has random features of 1.2, that will definitely make your eyes go twinkling if you used 1.1 and never knew anything about 1.2. Having said that, I have the perfect link to follow: OCPHP. These are the presentation slides on 1.2 in the recently held OCPHP conference. A must see for any 1.2 wanna be.
Validation
One area where CakePHP 1.2 has really improved is in the built in validation support. In 1.1 there where only four validation rules: VALID_NOT_EMPTY, VALID_NUMBER, VALID_EMAIL and VALID_YEAR. The rest had to be hand coded. In 1.2 there are more validation rules than you will ever need: alphanumeric, email, maxlenght, url and phone are a few to name. To get a better picture of all the available rules and how to use them, follow the links below:
- Validation with CakePHP 1.2 by Cakebaker again.
- All about Validation in CakePHP 1.2 by Another Cake Baker.
- All about Validation in CakePHP 1.2 - Part 2 by Another Cake Baker
- Validation Gotcha in CakePHP 1.2 by Another Cake Baker
- Multiple rules of validation per field in CakePHP 1.2 by Mariano Iglesias
Caching
Cool! Enough of validation, and now its going to be something that is becoming more important as CakePHP is being used in high traffic web apps: caching. Proper caching of data can make your app improve its performance dramatically. CakePHP 1.2 comes with caching support right out of the box. At the moment, it has support for five different caching engines:
The default caching engine is file i.e. it uses the files to cache data. But, the most elegant thing about the 1.2 caching support is that it has a common interface for all the caching engines. You can change the caching engine and yet use the same code to cache. Also, you can use any other caching engine with the same interface. You can even combine all the caching engines appropriately by writing our own engine by wrapping different caching engines into it. Switching caching engine in the runtime is also possible. What else can you ask for? Links? Here they are:
- CakePHP 1.2 Cache by Jiri Kupiainen
- Optimizing your CakePHP elements and views with caching by Tane Piper
- Cache Elements Individually For Each User by Ketan
Console
If you have used the bake.php script in 1.1, you will be amazed by the new console of CakePHP1.2. Basically, what the bake.php script did was that it allowed you to create models, controllers and view file structure ready for you(this is more commonly called baking) so that you have a structure ready for you to start working on. The new console takes this to the next level by allowing you to not only bake(auto generate code), but gives you access to different code from the command line. You can even use it to automate different tasks. This is something that I will most definitely write about more in the future, but for the time being, these links will satisfy your thirst:
- Setting Up the CakePHP Console on Windows. this is a screencast from the CakePHP site
- Setting Up the CakePHP Console on *nix, another screencast
- Update(31/08/07): Baking a bit faster with the bake script by Cakebaker
- Update(31/08/07): Faster baking of controllers with the bake shell script by Cakebaker
- Update(31/08/07): Baking Views by Cakebaker
Test Suite
Unit testing is something that has become vital for cooking bug-free(bug free? Im definitely kidding) apps. CakePHP 1.2 has integrated CakePHP test suite that uses SimpleTest. There isn’t much(just one) docs for this yet, but I am sure that this feature is so important, that proper docs will be available very soon. May be I can chip in ;). For the time being this is the only link I found, and it is from the bakery: Testing Models with CakePHP 1.2 test suite by Mariano Iglesias .
Wow! I cant believe you are still reading. I am already becoming tired of writing, so you must be tired as well, but thanks for being with me
Frankly, I didnt expect this to get this long, but I still have some more links to write about. Don’t worry, I will be quick from now on
The ‘With’ Association
[Update(06/09/07)]
The ‘hasandbelongstomany’ relationship has been one of the most confusing aspects of model relationship in CakePHP for quite sometime, but (hopefully) not anymore. The ‘with’ association is here to make life easier. So what is it? It is nothing more than an easy way to access the join table. With the ‘with tag’, you can directly access the join table without any hassle. Some of the details are discussed by Chris’ Brain in A Glimpse Inside CakePHP 1.2
RSS Feeds
Making RSS Feeds for your app cant get easier. Super-easy RSS feeds with CakePHP 1.2 by Jiri Kupiainen and How Easy Are Web Services in CakePHP 1.2? Really Easy! by Chris Hartjes explains it all. Don’t forget to go through the comments.
Pagination
In CakePHP 1.1, pagination was not present in the core. With 1.2, pagination is right at home as Rob Conner explains in Basic Pagination Overview (1.2) and Advanced Pagination (1.2). Update(30/08/07): I cant believe I missed this wonderful article by Nate: Pagination, etc.
Authentication and ACL
Authentication and Access Control List are explained in the following bakery articles:
Email Component
1.2 has a new Email Component: Brief Overview of the new EmailComponent by GreyCells
Helpers
Now with helpers. There is a new helper called FormHelper that is dedicated to you know what(Forms). Also, now the “dot” notation can be used(Model.field instead of Model/field). The links below shows the usage of different helpers in 1.2
- Html Helper by Jeff Keith
- Form Helper
- Javascript Helper’s JSON object by Eelco Wiersma
- Update(30/08/07): Form Building: More Auto-Magic Than You Can Handle? by Nate
The 1.2 Manual
Ok! Thats it! But before I let you go I have one final link. I am sure you are eagerly waiting for the 1.2 Manual to come out. The CakePHP people are hard at work to get it done. But, if you want to have a sneak peak at the work, just click here. It is still incomplete, but going through it will not harm.
Thats all I have. I plan to write more about each 1.2 features in more detail, but lets see how that one goes. If you think I missed any useful link, please do let me know. I will be glad to update. ![]()
You have made a great Cake here! really easy to eat. i would love to see a comparison between Cake 1.2 and CodeIgniter. because this is another pretty women who can make you cheat on your present girlfriend…haha. anyways thx for nice post. keep it up.
Thanks for this post. One correction: the article “Command line fun in CakePHP 1.2″ describes with bake2 a feature which is no longer available in CakePHP.
@Junal: I already did have an affair with the woman you mentioned, but she is nothing compared to my pretty lady
@Daniel: Thanks for pointing out. I have already removed it, making me more interested in writing something about the console
Brilliant article, well done.
I’ve been using 1.2 for 3 months with success and have a big app up and running, but there were links and techniques I hadn’t come across in here. This page is definitely in my bookmarks now!
@Ahsan: I wrote some articles about the new console, see http://cakebaker.42dh.com/tags/bake
@Howard: Thanx
@Daniel: Thanks again, I added your articles
Very nice post Ahsan, nice overview and reference!
and thanks for referring to my post
Great article!
I especially found the links about the test suite MOST informative. It’s really something I have to start doing.
Very nice piece of reading for someone (namely me) coding in 1.1 and wanting to swap to 1.2.
Thanks
hi
this is steve
I need the replace ment for this function
Digest::SHA256.hexdigest(password + user.password_salt) in php.
currently this is in Ruby on Rails.
Thanks
Steve
Thanks a lot for this compilation. Really useful!.
Pere.
Hi - I think you really capture the spirit of Cake here. Once you have grasped how everything works and start to get a bit of familiarity with the framework, you really don’t want to go back to old fashioned ways of working. I started using Cake about a year ago and now I build pretty much everything using it. When I have to go back and work with sites built with random collections of functions etc. my heart sinks - bad enough with the code I have written myself, god forbid I have to work with what colleagues and ex-colleagues leave behind.
Last week I discovered 1.2 - and I am gutted - I cannot believe that I have been using 1.1 all this time. 1.1 is great but as you say here there are so many great things built into the core of 1.2 - pagination, improved validation, ‘with’ support for HABTM relationships. Best of all the manual even in its half finished state is superb.
I just can’t believe it took me so long to get to 1.2
Cheers
John
Very nice overview! CakePHP is getting better and better… Well chosen title
1. blog tutorial of cakephp1.2 implemented fine.
2. Simple Form Authentication in 1.2.x.x by sean callan i have implemented on my system perfectly.
the question i have is how to protect all my pages(controllers) using this authentication mechanism
simply said is how do i check in my posts_controller or xyzController.
thanks
irfan
nicely presented article. why not arrange seminar at your office and invite our php team too.
so we could have more collaboration, perhaps.
best wishes,
@Hasan: thx Hasan bhia, I wud luv to do that