Starting A New Blog

Greetings to all who are reading this. If you have been following my blog, you already know how irregularly I write. But here I am, posting after a long time. But, this might be the last one I post here, as I am moving to a new location, and here is the official annoucement!

From now on, my irregular postings are going to appear here: http://ahsanity.com. So, if you are one of those few people who have added me to their feeds, its time to change the url.

I hope I will be less irregular from now on. So, wish me luck!!! :)


Making The Blog Tutorial Run on CakePHP 1.2

If you have ever tried to learn cake, the chances are that you have already gone through the CakePHP Blog Tutorial found in the manual. It in an excellent read to get acquainted with the cake way. But unfortunately, the Blog Tutorial only runs fine in CakePHP 1.1. If you try to run the code on 1.2, you will get errors as shown below, either when you add or edit post:

Blog Tutorial Error in CakePHP 1.2

The main reason for this is that functions like input(), tagErrorMsg(), textarea(), hidden() in the Html Helper are now deprecated. Instead, all the form related functions are moved in the Form Help.

So, to make the blog tutorial code run on 1.2, you just have to make the following simple changes:

  1. Load the form helper in the Posts Controller (/app/controllers/posts_controller.php):

    class PostsController extends AppController {
    var $name = 'Posts';
    var $helpers = array('Form' );
  2. Change the view of add (/app/views/posts/add.thtml) to:

    <h1>Add Post</h1>
    <?php echo $form->create('Post');?>
    <?php echo $form->input('title'); ?>
    <?php echo $form->input('body'); ?>
    <?php echo $form->end('Submit');?>
  3. Also change the view of edit (/app/views/posts/edit.thtml) to:

    <h1>Edit Post</h1>
    <?php echo $form->create('Post');?>
    <?php echo $form->input('id'); ?>
    <?php echo $form->input('title'); ?>
    <?php echo $form->input('body'); ?>
    <?php echo $form->end('Submit');?>

And thats it! Your blog tutorial code will be running smoothly on 1.2. One last thing, that I recommend, is to change the extension of all the views from .thtml (e.g. index.thtml) to .ctp (e.g. index.ctp). Though not doing so will not create any problem, but you better get use to the .ctp extension, as this is the defaut file extension for CakePHP 1.2 views.

For a more complete picture of the changes in 1.2, please visit: CakePHP 1.2: The Romance Continues…

Thats it! :)


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


Divitis and Classitis: Two new words in my CSS vocabulary!

Yes, “divitis” and “classitis” are the two latest words that I have added to my CSS vocabulary. But unlike normal language words, these two are added to make sure that I never use them, or atleast minimize their use.

So, what do they mean? Divitis is when someone uses unnecessry <div> tags in their markups. For example:

<div id="menu">
<li>First item</li>
<li>Second item</li>
<li>Third item</li>

The above example has unnecessary div element. Instead, it could have been easily done as:

<ul id="menu">
<li>First item</li>
<li>Second item</li>
<li>Third item</li>

Likewise, classitis is the over use of the class attribute. For example:

<p class="address">
Ahsanul Bari<br />
House-17, Road-3/A, Sector-5<br />
Uttara, Dhaka-1230<br />

In the above example, we could easily use the <address> tag instead of using the class=”address” like:

Ahsanul Bari<br />
House-17, Road-3/A, Sector-5, <br />
Uttara, Dhaka-1230<br />

The above two examples are really simple, but I hope you got the point. Avoiding divitis and classitis helps to write mark-ups, that are more semantically correct.


Getting Started With Fedora Core 6

Fedora Logo

If you just installed Fedora Core 6, and you are clueless what to do next, just relax and click the links below:

1. http://www.fedorafaq.org

2. http://ubuntuguide.org/wiki/Fedora_fc5

3. http://www.gagme.com/greg/linux/fc6-tips.php


Styling an input type=”file”: The Result

In my last blog, i talked about a hack that I found in an article, to style input of type=’file’. Well, I used the technique, and here is my result:



Isn’t it cool? :)


Styling an input type=”file”

If you are ever in a situation where you need to style an input element with type=”file”, you will be very surprised to find that almost no styling is possible directly. This is because, no browser supports styling for <input type=”file”>. Only the “size” attribute was there, that gave some control over its width. Other than that, I had no luck.

Lucky I stumbled upon this page: http://www.quirksmode.org/dom/inputfile.html. This has a very clever techique, that actually styles an input element of type=”text” and an image, makes the original input type=”file” invisible, and places it over the fake input, to give the impression of a styled file uploader. A very sexy hack indeed!


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,457 hits


Get every new post delivered to your Inbox.