CakePHP Book and Code Updates

Posted by Matt on Fri, Jun 12 2009

The Book

For anyone who missed it, I released a free CakePHP book a month ago. Since then it's been downloaded over 2500 times. I've also received some great feedback and have made a bunch of corrections to the code and grammar. The biggest change is that the table of contents is now links and will jump you right to the section. That's reason enough alone to grab the updated version. The new permanent home page for the book is here.

Interactive Console and DebugKit Panel

Github Link

http://github.com/mcurry/interactive

Updates

I fixed a couple issues that were pointed out in the comments of the announcement post.

One of the suggestions was to have the up arrow cycle previous commands when using this in the console. It's a great idea and actually works magically on ForTheWindows. I checked it out and I didn't see a way to make it happen for all systems though. So, I did the next best thing. Hitting enter on a blank line re-runs the previous commands. Entering 'h' brings up a list of the last 20 commands and you can run one by just entering the number. Command history is also saved across sessions, so you can exit and go back in and still run old commands.

Custom Find

Github Link

http://github.com/mcurry/find

Pagination

I pulled in some of the ideas from Daniel Salazar's post and now the custom find types have built in pagination support. It's kind of scary how easy it is. Here's an example:

$this->paginate = am($this->paginate, $this->Post->find('published', array('paginate' => true)));
$this->set('posts', $this->paginate());

This only works if you are still using one of the default find types to run the actual query, as opposed to Model::query();

Extending Model

I struggled with how to make this plugin easy to install. I didn't want to force people to have to copy and paste a bunch of code into their AppModel. I felt like that would make updates harder and would just make AppModel too messy. So instead I recommend that you have your AppModel extend FindAppModel instead of Model. FindAppModel in turn extends Model. Multiple inheritance would come in handy here.

Ajax Chat

Github Link

http://github.com/mcurry/chat

Updates

A couple small changes here. The helper now handles cake installs that aren't running in webroot automatically, so you don't have to set it in the JavaScript manually. Also the posted chat message now appears instantly in the chat window. Before you'd have to wait for an update for the message to appear.

Asset

Github Link

http://github.com/mcurry/asset

Updates

The order that scripts and codeblocks is now maintained. The previous version always put codeblocks after scripts, but there are times when the codeblock needs to go before a script. The new version keeps everything in the order that it was entered. This means if you do script1, codeblock, script2 that the two scripts won't be merged because it is assumed that the codeblock is dependent on script1 and script2 is dependent on the codeblock.

JS Validate

Github Link

http://github.com/mcurry/js_validate

Updates

I merged a couple changes from javierm's fork. These include a fix for the numeric check, matching Cake's default error HTML and including the fieldName when calling custom rules, which should make doing Ajax validation much easier. I'll have a post showing some examples of this next week.

Posted in CakePHP

5 Comments

Javier said on Jun 12, 2009
Quick note: your "asset" plugin link points to your "find" plugin.

"So instead I recommend that you have your AppModel extend FindAppModel instead of Model. FindAppModel in turn extends Model. Multiple inheritance would come in handy here."

Yes, I've run into this very same problem. If you've got two plugins which extend the functionality of the Model class, there's no way to apply both of them at the same time to your AppModel. I guess that's what behaviors are for, but sometimes a behavior doesn't make much sense.
Matt said on Jun 12, 2009
Thanks, fixed the link.

Yea, behaviors work well in most cases, but not when you need to override a core function.
Mike said on Jun 12, 2009
Hey Matt,
Love the Asset Packer plugin but I've noticed an issue regarding the order of scripts while in debug mode.

For example, I have the yahoo-dom-event.js included in my default layout as my base library, and then in my views I link to specific modules such as connection-min.js, etc. When debug mode is off, the Asset Packer packs them in the proper order and everything is perfect. When in debug mode, the order of these scripts in incorrect. It first loads the scripts included in views, and then the layout is loaded last. This doesn't work since the modules are dependent on the base library.

Thanks again for a great plugin,
-mike
Matt said on Jun 12, 2009
I'll check it out. Thanks.
Sean said on Jun 14, 2009
Thanks for the updates to your book, some really cool stuff in there which is coming very handy already.