CakePHP 1.2RC3 Released

Thanks to the power of Twitter I found out that The Show for CakePHP was resuscitated and brought back to life last night. I listened to the (surprisingly short) show, the main thrust of which was that CakePHP 1.2RC3 was released last night. Why should you care?

Well, maybe not so much on the last item but it’s ALWAYS good to see any project make a significant release. 1.2 has been in the works for more than 18 months, which seems to many to be way too long. I’m not so sure I share that sentiment. If the goal is to try and produce quality releases, then “it’s done when it’s done” is a reasonable answer. I’m sure this is not a new argument, so I won’t get into it here.

My own contributions to RC3 have been, what’s the word…non-existent. Non-computer hobbies + side work = no time to contribute to Cake. I found out that commit access for people who haven’t contributed anything in more than 60 days has been revoked, but that’s really just a minor annoyance. I’m sure I could get it back by asking nicely and actually having something to contribute.

But I think I’ve gotten back into Cake developing at the right time as I caved in and decided that my long-rumoured plan-a-road-trip site shall be built in CakePHP after all. Yes, I’ve been playing around with Django but I’m violating one of my favourite rules: Just Build It, Damnit! I’ve been fooling around with Balsamiq Mockups to do the pages and are now digging around for helpers to do the mapping mashup I need. If you want to mock me over how little progress I’ve made, feel free to visit the site. If you’d like to get involved at all (I could use some help on the “make a pretty UI for it” front) let me know.

Article Tags >> ||

Komodo and CakePHP

For those who remember how I was an editor waffler will remember that I play around with Komodo from time to time, and decided to get back into using it again. There are alpha 5.0 versions available so I downloaded one and tried it out. Seems to be less resource hungry than previous versions (as in it doesn’t cause my fan in my MacBook to start up every time I open Komodo). Now, since I know a few people at Activestate I emailed Jeff Griffiths to ask him a few questions. He responded by hacking together something very quickly for adding code intelligence for CakePHP to your views. If you’re a Komodo user (or are interested in trying out Komodo), try it out and let Jeff know how it’s working out.

Article Tags >> ||

Book Review: CakePHP Application Development

A few weeks ago I was approached by Pakt Publishing and asked if I was interested in reviewing the recent CakePHP book ‘CakePHP Application Development’ by Ahsanul Bari and Anupom Syam. In the interest of full disclosure, I have communicated with Ahsanul a few times via the CakePHP mailing list and on Twitter. We’re not total strangers, more like casual acquaintances who know each other through the CakePHP community.

One of the biggest criticisms in the past of CakePHP was the lack of published documentation on how to use the framework. As shocking as it was to me, there were people who preferred a paper copy of the Cookbook so they could have access to it when they might not be online (what, working on your computer and not online?!?) or to read offline. Naturally, several books about the framework have been published in the past few months, and I can’t think of a better book to recommend to people interested in learning the framework than this one. And I’m not just saying that because I got a copy for free. While the book is good, there are a few places where it could be even better.

The Good: Examples, Example, Examples

The target audience for this book is the right one that CakePHP is attracting: intermediate PHP developers who may have not used a framework before and are trying to figure out how to use one to their advantage. Without clear and relevant examples of how to use it, CakePHP would be just another framework struggling to gain acceptance with the PHP deveoper community. If you want examples on how to do most basic things with CakePHP, this book has them. Want to know how to configure CakePHP to work for your web server? Check! How do you get results from your database? Check! How do you use the ‘bake’ utility from the Cake console? Check! Validating form fields? Check!

I feel that the examples in this book are it’s strengths. The code is well written and every code example is followed by an explanation of what they are doing. Many times the example is not enough, you have to understand WHY it’s written that way.

The Good: Sample Applications Always Help

Almost half the book is devoted to creating an application from scratch, including configuring the often-misunderstood Auth component and showing how the built-in Javascript helper allows you to add Ajax-powered functionality via the Prototype and Scriptaculous Javascript libraries. Seeing an application being built from start to working prototype is an invaluable lesson for the “learn from example” crowd.

The Bad: Less Info On Doing Things The Cake Way

I feel that some more time could’ve been spent explaining CakePHP’s “convention over configuration” preferences and how it changes the way you approach building an application using CakePHP. Perhaps that wasn’t a topic for this book’s intended audience, since it’s only the deep thinkers and the rant-and-ravers (which I have been accused of belonging to) who like to discuss the philosophy behind CakePHP and the question of just what a framework is good for.

The Bad: Thin on Server Configuration Information

While there is a chapter devoted to getting CakePHP up-and-running using Apache and MySQL (specifically using WAMP), it would’ve been very helpful to see an example of the type of configuration recommended for production environments, where the APP directory is web-accessable while the CakePHP core is located somewhere outside the webroot, linked in via an option in the configuration files.

The Bad: No mention of the differences in debug levels

When I do my development work on a CakePHP application, I set the debug level to 1 so that I see all errors and the SQL statements being generated by my models. In production I have the debug level set to 0 as I don’t want error messages on the screen that reveal any information, and I certainly don’t want people seeing the SQL statements being executed. Sure, it’s security by obscurity but it’s also debugging information that’s cluttering up the screen.

The Bad: No mention of using the built-in testing

While I’m a lapsed tester, the fact that CakePHP will create the shells for writing unit tests for the models and controllers you create should not be overlooked. Although testing gets a bad rap (”It’s too hard, and it wastes my time!”) it’s a programming practice that should be encouraged.

The Ugly: CakePHP is still a moving target

While this in no way diminishes the efforts put in by the authors to create this excellent introduction to CakePHP, at the time it went to press CakePHP 1.2 was still not feature-final. Some tihngs have changed, and I expect some more things will change before CakePHP 1.2 is finalized and work on CakePHP 2.0 starts. This is the danger in writing about any programming language: the information could become obsolete at any time. But don’t get all upset about it, as it is likely only very minor details that have changed. The CakePHP core team does try to not break things *that* much.

So, don’t let the number of “bad” issues above dissuade you from checking out this book. The items I highlighted are probably bettered suited for a “Advanced CakePHP Application Development for Grumpy Developers” book. I would not hesitate to recommend this book to any semi-experienced PHP developer who is looking for a resource guide to get themselves started.

Article Tags >> ||

Don’t Fear The Command Line: Using CakePHP Shells

(Note: this is a reposting of an entry I made when trying out Habari as my blog software. If you missed it, I hope you enjoy it now.

For a consulting job I'm working on where I'm porting a spaghetti-PHP application over to using CakePHP I am moving their existing authorization system over to using Cake's Auth component. Of course, they are storing all their passwords in plaintext in the user account table, so I needed an easy way to convert all the existing passwords over to be encrypted using the same hash that Auth would use. Doing this was surprisingly easy thanks to the power of shells and tasks in CakePHP..

PHP:
  1. /**
  2. * Shell for encrypted naked passwords with the correct hash for use
  3. * with the Auth component
  4. *
  5. * @auth Chris Hartjes
  6. */
  7. class EncryptPasswordsShell extends Shell {
  8.     var $uses = array('UserClient');
  9.    
  10.     function main() {
  11.         App::import('Core', 'Security');
  12.         $this->out("Starting to encrypt passwords\n\n");
  13.         $this->UserClient->recursive= -1;
  14.         $users = $this->UserClient->find('all');
  15.        
  16.         foreach ($users as $user) {
  17.             $userName = $user['UserClient']['username'];
  18.             $password = $user['UserClient']['password'];
  19.            
  20.             if ($password != '') {
  21.                 $data = array('UserClient' => array(
  22.                     'id' => $user['UserClient']['id'],
  23.                     'password' => Security::hash($password, null, true))
  24.                 );
  25.                
  26.                 if ($this->UserClient->save($data)) {
  27.                     $this->out("Updated password for {$userName}");
  28.                 }
  29.             } else {
  30.                 $this->out("Bad password for {$userName}");
  31.             }
  32.         }
  33.     }
  34. }

I think the code in there is pretty self-explanatory. The only "gotcha" I ran into (fixed by a look at the Auth component itself) was that I needed to tell Security::hash() that I wanted to use the salt I defined in my config file. By default that parameter is set to false, hence the need to explicitly set it to true.

Thank to Mark Story for pointing me in the right direction for this.

Article Tags >> ||

CakePHP Workshop

For those who might not look at the same obscure blogs that I do, I thought I should mention that the last few spaces for the first CakePHP Workshop in Raleigh, NC are filling up so if you want to learn CakePHP straight from the people who help to build it, this is your best bet. Sadly, I will not be in attendance. ;) If they hold one closer to Toronto I'll probably come out.

Article Tags >>
Want to advertise on this blog? Send email to chartjes@littlehart.net
GTcars Canadian Car Audio TurboDodge Car For Sale Sign
Audi Forum Mustang Forum Dodge Intrepid Miata Turbo
GTscene Pontiac Bonneville


@TheKeyboard is Digg proof thanks to caching by WP Super Cache!