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.

Popularity: 96% [?]

Bookmark This Post

del.icio.us Digg FURL Yahoo! My Web 2.0 Reddit

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.

Popularity: 37% [?]

Bookmark This Post

del.icio.us Digg FURL Yahoo! My Web 2.0 Reddit

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.

Popularity: 83% [?]

Bookmark This Post

del.icio.us Digg FURL Yahoo! My Web 2.0 Reddit

CakePHP + SimplePieI’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.

Popularity: 67% [?]

Bookmark This Post

del.icio.us Digg FURL Yahoo! My Web 2.0 Reddit

LayoutsOn my old blog I kept a subdomain that I called the “sandbox”. It was a standard CakePHP installation, where I could post plugins or code that I intended to release. Since the old blog is deprecated, I wanted to port the sandbox to this blog, basically give it a design that matched. This is normally pretty straightforward, so to up the degree of difficulty I decided to keep the old design as well and automatically switch the layout based the domain.

To accomplish this I created a simple layout switcher component that determined the domain and uses that information to select the correct layout. All you have to do is include it in your controller and it will automatically do the rest.
Most likely you want to apply it to your whole site, so you should put it in your app_controller. Full instructions and downloads are available on the sandbox

Now if you go to sandbox.pseudocoder.com you’ll see a different layout then sandbox.siteamonth.com.

Popularity: 68% [?]

Bookmark This Post

del.icio.us Digg FURL Yahoo! My Web 2.0 Reddit

I have updated the CakePHP Ajax Chat Plugin to v1.1. The only change is some javascripting to add the message immediately to the chat window. This should solve the biggest complaint where the chat appeared slow or delayed.

Popularity: 13% [?]

Bookmark This Post

del.icio.us Digg FURL Yahoo! My Web 2.0 Reddit

I try to do an RSS feed for every site I make and I realized the code is pretty much the same for each site, so I made it into a plugin. It’s pretty easy to use will work out of the box for most sites, I think. I also allowed for some configuration by editing the model that will be providing the data for the feed. Check out the full code and instructions for the CakePHP Automagic RSS Feed Plugin and let me know what you think!

Popularity: 14% [?]

Bookmark This Post

del.icio.us Digg FURL Yahoo! My Web 2.0 Reddit

I’m really enjoying working on camXip and since I haven’t completed nearly as many features as I’ve wanted to, I’m going to keep working on it through February and maybe longer. I’ve contracted a professional designer to do the logo and a couple friends are going to be working on the site as well. I’ll probably be splitting the blog off at some point as well.

In the meantime I’ve been working on some other CakePHP plugins that I’ll be releasing. The next one is an automatic RSS feed generator and I may release the user/login system I use for pretty much every project at some point.

Popularity: 14% [?]

Bookmark This Post

del.icio.us Digg FURL Yahoo! My Web 2.0 Reddit

I’ve posted the code for an Ajax chat plugin for CakePHP at the SiteAMonth Sandbox. It’s really pretty basic, but works well enough and can be styled using CSS.

A couple of thoughts for improving it:
1) Some sort of spam protection.
2) When the user posts a message there is a moment before it shows up in the chat window that may be confusing.
3) New messages show up at the top. I think users are more accustomed to seeing new chat messages at the bottom. It is easy to switch, but javascript will have to be used to auto-scroll to the bottom.

If you have any questions, comments or bugs please leave a comment.

Popularity: 15% [?]

Bookmark This Post

del.icio.us Digg FURL Yahoo! My Web 2.0 Reddit