Sandbox
CakePHP Ajax Chat Plugin - Updated for RC3 and Now Using jQuery
It's past my bedtime so this will be short. I wrote an Ajax chat plugin for CakePHP a few months ago. It wasn't working so well with RC3, plus it used Prototype, so I decided to fix it up for RC3 and switch to jQuery.
Automagic JavaScript Validation Helper - Beta
Way back when CakePHP had a wiki there were a series of articles on "Advanced Validation." One aspect of these articles was using the Model rules in JavaScript to validate on the client side. The code (I believe this is it) was originally for CakePHP version .10 (iirc). I had been using a heavily modified version of this code even in my 1.2 projects, but it was due for a ground up re-write.
I wrote an article for PHPArch not too long ago with a generic PHP approach for JavaScript validation. Using that JavaScript as a base, I created a helper to convert the model rules into JavaScript.
Here are the links:
Download
Instructions
Demo
This is all very beta, so please let me know if you find an issue. The helper should work with the three formats for defining validation in your model (output from bake, one rule per field, multiple rules per field).
If you are worried about security, there is an option to only include certain rules. See the tips section at the end of the instructions. Thanks to Marc for suggesting this.
CakePHP Asset Helper Updated
I've been using this helper on some projects lately and ran into a few issues, plus there have been some good comments, so I figured it could use a few tweaks. The new version is available for download on the Sandbox page.
Change Log
- Removed deprecated DEBUG, using Configure::read('debug') instead.
- Strip "." from file names. This seemed to be causing problems with IE7.
- Option to MD5 outputted file name.
- Debug flag.
- Packed files now have seperator lines.
- Improved .htaccess included. Based on the comment by Marcin Domanski on the CakePHP Bakery.
Automatic JavaScript and CSS Packer Helper for CakePHP
Download
http://github.com/mcurry/cakephp/tree/master/helpers/asset
The Story
A little while ago I wrote a post about how I manually combine/pack Javascript files. Even as I was writing it I was thinking "hey, this would be a great CakePHP plugin/component/helper. Before I could code it Brad Daily beat me to it. However there are a couple of things I didn't like about his method, particularly the need for configuration files (how anti Cake!) and the need to run a console script to generated the packed versions.
My First Solution
Suitably inspired I whipped up my own version. And it was awesome. It was so friggen automagic that you didn't even have to change your code. Just include the helper and it did the rest - assuming you were using the new (as in Cake 1.2) scripts_for_layout syntax and not adding your scripts inline.
The Snag
Unfortunately I had missed a small issue. Since the helper relied on the afterRender callback to do most of the work any js/css added in the layout was missed. See the afterRender is called after the view is rendered, but BEFORE the layout is rendered. Doh! Digging through the base helper I saw a promising callback, afterLayout. After a bit more digging I found that this is merely a placeholder (added sometime around new years) and isn't actually called anywhere. I'm not sure if it would have worked in my case anyway, since I really needed something like duringLayoutHeaderRender callback.
My Second Solution
So I reworked the interface of the helper. It's less automagic now, but works with scripts from both the layout and view. Basically instead of just echoing $scripts_for_layout you use the helper. Otherwise you still include JavaScript and CSS as normal, making sure to set inline to false. Full directions and an example are in the Sandbox as usual.
Pros and Cons
I like Brad's helper better for certain projects. Particularly ones that uses a large amount of JavaScript, as his photo manager app does. But I think for most small sites, with just a few files the automatic approach works out better. Plus mine packs CSS files in addition to JS. This is probably a good time to mention that Brad's app, SlideShowPro, is totally awesome. I recently used it when developing AndrewSaul.com. Basically I went from no photo gallery to full featured, cool looking, seamlessly integrated photo gallery in thirty minutes. Seriously, I was shocked when I read this was the product of just two guys working nights.
Bringing It Home
Checkout the helper. It's kinda cool. The Sandbox jumped from a 64 to a 79 in YSlow after I applied it. I also included an .htaccess file that handles things like gzip, expire time and ETAGS. Unfortunately my host doesn't support any of those, so I didn't get any benefit from it.
SimplePie CakePHP Component
I'm working on a new design for my personal site, mcurry.net, part of which is basing the site on CakePHP. Although Cake is probably a little overkill in this situation, I've taken to using Cake for pretty much any site. The pretty urls alone make it worthwhile. And sites that start out as a single static page have a way of growing.
Part of the site is going to show the feed for this blog. SimplePie is the slickest PHP class for parsing RSS feeds. Using the class with Cake's vendor system was an easy call. While I was on the SimplePie site I came across a this component, which unfortunately wasn't up to date with the latest version of SimplePie.
I've updated the component to work with the SimplePie 1.0.1 and CakePHP 1.1 and 1.2. The updated SimplePie CakePHP component, along with instructions are now available.
