JQValidator – CakePHP Client Side Validation

CheckmarkJQValidator is a plugin for CakePHP used for a client side validation of a CakePHP model, written in jQuery. It’s main purpose is to validate the inserted information prior to their submit to the server, this both reduces the number server requests and makes your application faster and more user-friendly.

The plugin is still in an infant phase of the development, supporting validation for only the following data types:

  • notempty,
  • numeric
  • date

But with further development needs, I will update the plugin accordingly. Any help from anyone else is also appreciated.

JQValidator is available on github. For more information on the functionalities, installation and usage read the JQValidator plugin wiki.

Generate an URL from the controller and action name with CakePHP

CupcakeFirst of all, I am quite sure that there is another way to do this, and those who know must have said “This boy is dumb as a bag of hammers”. Some might even say, “you can generate a link with the Html helper”, yes I know, but I need to generate an URL not a link, for example when I want to add an AJAX call to a specific location within my CakePHP application.

Anyway, until you drop me a comment on how to do this anyhing better, I may reccommend this method. I have created a helper class, that incorporates the HtmlHelper’s link method and gets the url using regex.

Helper class

< ?php
class UrlBuilderHelper extends AppHelper
    var $helpers = array('Html');

    function build($options)
        $linkHtml = $this->Html->link('title', $options);
        $regEx = "/<a href="(.*)">.*</a>/";
        $matches = array();
        preg_match($regEx, $linkHtml, $matches);
        return $matches[1];

More on generating URLs in CakePHP…

Case Fix plugin for SubTitle Workshop

For all of you working with subtitles, fixing, translating, synchronizing, etc. You’ve probably heard of SubTitle Workshop application from http://www.urusoft.net/. Heard or not, it’s a great tool for manipulating textual subtitle files.

SwitchI recently had a need for a tool which will convert a subtitle file completely written lower-case (ex: this is a completely lower-case sentence. and this is another one… and yet another one.) letters to a “normal-case” (ex: This is a completely lower-case sentence. And this is another one… And yet another one.) Some may say that there is a Case fix functionality implemented in the program itself. Yes I know, and it don’t work for the character set I’m working with and it would just ignore those letters that are not covered by the character set the program is using.

So if anyone wants a plugin for SubTitle Workshop that will fix case on the first letter of each sentence that works with all characters, use this:

Sentence First Letter Case Fix for SubtitleWorkshop

If by some chance this plugin does not cover all characters, feel free to drop me a comment, or even fix it yourself, publish it, whatever you want, this is released under Public Domain License.

Using multiple column primary key in CakePHP (cascade delete problem)

ReviewI guess you stumbled here because you want to know can you use a primary key in your CakePHP model made of two or more columns.
Well… You can’t, at least in the the CakePHP 1.3, at least I couldn’t, and if you can, let me know, because that would be awesome…


Anyway, I know I tried to have a table like this:

CREATE TABLE `projects_users`
    `project_id` int(10) unsigned NOT NULL,
    `user_id`    int(10) unsigned NOT NULL,
    `attr`     int(10) unsigned NOT NULL,
    PRIMARY KEY (`project_id`,`user_id`)

Unlike in all CakePHP projects, I wanted to have a regular HABTM mid-table like I would have had in SQL Server for example. I even saw a web-page (instead of reading this) that described how to use multi-column primary key in CakePHP by adding the $primaryKey value (like below) to your model (in my case “ProjectsUser”):

< ?php
class ProjectsUser extends AppModel
    var $name = 'ProjectsUser';
    var $primaryKey = array('project_id','user_id');
    var $belongsTo = array
        'Project' => array
            'className' => 'Project',
            'foreignKey' => 'project_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        'User' => array
            'className' => 'User',
            'foreignKey' => 'user_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''

Great success… NOT.

So I’ve been working and working on the MVC’s related to this this table, with no problems, until I saw that the cascade delete didn’t work on this table. I didn’t even saw any errors displayed, but it just didn’t work.
More on using multiple column primary key in CakePHP

My experience with CakePHP

“My experience with CakePHP”, sounds like a school assignment we always got when we got back from the summer leave… Anyway I’ve been using CakePHP framework for some time and I have realized that I looked for the same things (how-to’s, helpers, bug fixes, etc…) several times.

Well, not any more, whenever I “discover” something, no matter how embarrassing I’ll try to write it down, it will help me not to forget, and I hope that it helps someone sometime…