11 Dec

A better way to send emails than CakePHP’s default Email Component ?

Best Practices, CakePHP, Latest Developments

While working on a big project today, I had to use this default Email component. I was disappointed when I had to create two views for every singly mail... This is really bugging.. Plus, It is not fast as it can be.
At the same time, I've always loved the magic Model functions: findAllby

Today, I realized how productive it would make us if there's some similar magic functions for email as well. Say to send a user approval letter, you just have to write following in your controllers:

PHP:
  1. $this->Email->send_UserApproval($email, $verification_code)// to send user approval mail
  2. $this->Email->send_UserWelcome($email)//welcome mail
  3. $this->Email->send_AdminPaymentNotification($from);   // payment notification to admin

This does not only increases the speed of writing code, but also makes code look beautiful.

While I was thinking about the idea, I dugg into model class of CakePHP to find how its done, I found the source of magic:

PHP:
  1. function __call($method, $params, &$return) {
  2. $db =& ConnectionManager::getDataSource($this->useDbConfig);
  3. $return = $db->query($method, $params, $this);
  4. if (isset($this->__backAssociation)) {
  5. $this->__resetAssociations();
  6. }
  7. return true;
  8. }

This is the function which creates all Model:findAllby functions. So I decided to write my own component which will definately save time in many of the projects.

One good way of developing this would be creating a language/email file like emails.php with something like this:

PHP:
  1. 'user'=>array(
  2. 'Approval'=>'Hi user, You are about to get approved.',
  3. 'Welcome'=>'Welcome user, you can now play with our system.'
  4.  
  5. ),

This file will be read by Email::__call() and our magic functions will be created on the run.

What do you think of this method ? Is it better than current Email component ? I'll blog again as soon as my email component is ready..

10 Dec

Whats this fight going on in CakePHP team ?

CakePHP

I recently came across Daniel's post, I see he did made a good point about a function not doing something which it was supposed to do. But this post has turned to a fight against Daniel and other core developers. I personally give most of the credit to Daniel (cakebaker.42dh.com) for me to teach CakePHP through his blog. He recently left CakePHP development team, but his contributing efforts to blog about CakePHP, had been wonderful.
This was not just the first time, when I've seen other Cake developers doing this thing in public. There had been previous threads on same talks and insults from long.
Cakebaker deserves much more credit in the community as the others do.

24 Oct

10 Best CakePHP snippets for Web2.0 development

CakePHP

I've compiled a list of all code snippets in CakePHP which help me doing things faster in Cake. I hope this will be helpful for you too.

1. Tag Cloud: Web2.0 way of showing tags.. This customizable snippet will allow you to add tag cloud easily.

2. AJAX Auctocomplete: Another basic requirement of the latest web technologies. Also check out the Autocomplete article to implement the same.

3. AJAX Star Rating: This is a great one, lets you implement the rating system with your Cake application very fast and without any pain.

4. AJAX Chat Plugin: This is my favorite one, lets you implement AJAX chat easily - this can serve so many purposes in an application.

5. Flickr Gallery: This is a great article by Jonathan Snook. Lets you create a flexible attractive gallery with your own application.

6. GeoCoding: Good for mashup applications which uses Google Maps or Yahoo maps.

7. Ajax Validation Component: This component adds a few validation options to CakePHP validations. And yes, its more web2-ish.

8. Lightbox Effect Helper: Easily implement lightbox effect to your links and images.

9. Google Map Helper: Lets you add Google Map to any application in no-time, lacks flexibility, but speeds up the implementation process. This was developed by me.

10. jQuery Helper: jQuery is designed to change the way that you write JavaScript.

Please feel free to add up more to the list.

Additional Stuff:

1. Submit forms with AJAX in CakePHP
2. Enable SOAP Services in Cake
3. RESTful Web Services With CakePHP

Hire us

Contact us to get a free quote on your project.