CakePHP 1.2: The Romance Continues …


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.


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.


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:


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:

  1. File
  2. APC
  3. Memcache
  4. Xcache
  5. Model

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:


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:

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

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.


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


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

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. :)

About these ads

22 Responses to “CakePHP 1.2: The Romance Continues …”

  1. 30 August, 2007 at 12:12 am

    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.

  2. 30 August, 2007 at 1:04 am

    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.

  3. 30 August, 2007 at 2:30 am

    @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 :)

  4. 4 Howard
    30 August, 2007 at 3:00 am

    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!

  5. 31 August, 2007 at 12:22 pm

    @Ahsan: I wrote some articles about the new console, see http://cakebaker.42dh.com/tags/bake

  6. 31 August, 2007 at 6:24 pm

    @Howard: Thanx :)

    @Daniel: Thanks again, I added your articles

  7. 3 September, 2007 at 1:09 pm

    Very nice post Ahsan, nice overview and reference!

    and thanks for referring to my post :)

  8. 5 September, 2007 at 2:03 am

    Great article!

    I especially found the links about the test suite MOST informative. It’s really something I have to start doing.

  9. 9 mszajbe
    5 September, 2007 at 2:37 am

    Very nice piece of reading for someone (namely me) coding in 1.1 and wanting to swap to 1.2.


  10. 10 Steve
    21 September, 2007 at 4:44 pm

    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.


  11. 31 December, 2007 at 9:39 pm

    Thanks a lot for this compilation. Really useful!.


  12. 30 January, 2008 at 3:11 pm

    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



  13. 13 cakephptips
    11 March, 2008 at 2:22 pm

    Very nice overview! CakePHP is getting better and better… Well chosen title :)

  14. 14 irfan
    30 March, 2008 at 12:29 am

    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.



  15. 19 April, 2008 at 10:33 pm

    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,

  16. 21 April, 2008 at 10:09 am

    @Hasan: thx Hasan bhia, I wud luv to do that :)

  17. 11 June, 2009 at 7:04 am

    Well you all seem knowledgeable so I was wondering if you could help me out! I am struggling with having the authComponent use email instead of username for login. Cake Version 1.2

    This is what I have in app_controller:
    var $components = array(‘Auth’);

    function beforeFilter() {
    $this->Auth->fields = array(
    ‘username’ => ‘email’,
    ‘password’ => ‘password’

    This is what I have in login.ctp:
    echo $form->create(‘User’, array(‘action’ => ‘login’));
    echo $form->input(‘email’);
    echo $form->input(‘password’);
    echo $form->end(‘Login’);

    I have verified that the registration is working – db is storing users perfectly w/ hashed password. Even after changing the fields in the app_controller before filter, I am getting “Login failed. Invalid username or password.” as the auth flash message.

    Someone please help! – I can not believe I am running into a roadblock so early on…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


I no longer maintain this blog. Please visit my new blog at http://ahsanity.com

My Book on CakePHP

If you are looking for a book to get started with CakePHP, then this book is definitely what you need :)
10% off at the publisher's site.

Blog Stats

  • 159,452 hits


Get every new post delivered to your Inbox.

%d bloggers like this: