zen of coding

cakephp validation

Key/value tables and how to use them in CakePHP 1.3

The key/value tables (EAV model) are a nice a approach to database modeling, when we need to store some arbitrary data about another model. For example, let’s take a User model. We could create a single users table to hold all of the potential data or even create an additional[…]

Read More »

JQuery in the CakePHP world (part 2 – is client side code all that great?)

(part 1) Now, how is this an introduction to jQuery + CakePHP?… well, let’s see in a minute. First, I’d like to say that with the advent of frameworks such as jQuery, better browsers, which do a nicer job of supporting standards, and even faster PC’s and larger/better monitors, we[…]

Read More »

'required'=>true… the source of major confusion

In all the time I’ve been following cake on IRC (almost daily), it has become very clear that other than ACL and maybe Auth, ‘required’=>true in the model validation is the most confusing part of CakePHP for many people. On IRC it comes up, probably, once a week… even from[…]

Read More »

'required'=>true… the source of major confusion

In all the time I’ve been following cake on IRC (almost daily), it has become very clear that other than ACL and maybe Auth, ‘required’=>true in the model validation is the most confusing part of CakePHP for many people. On IRC it comes up, probably, once a week… even from[…]

Read More »

Set::merge() and dynamic validation rules

Here’s another trick with Set::merge()… Let’s say we’ve defined some basic validation rules in our Profile model, something like: var $validate = array (    ‘name’ => array(       ‘rule’ => array(’notEmpty’),       ‘required’ => false,       ‘message’ => ‘Please enter a name’  […]

Read More »

notEmpty validation rule

With the recent changeset (https://trac.cakephp.org/changeset/7399) a new, ‘notEmpty’, validation rule is now available. As you can guess, it checks to make sure that a field contains something other than a white space. You will have to upgrade to the latest build, to ensure that this rule is available in your[…]

Read More »

Validating a checkbox in CakePHP 1.2

In a few simple words: use the ‘comparison’ rule to validate a checkbox. To give you an example, let’s say a user needs to agree to the terms of service when registering a new account. In your User model you setup a rule for the checkbox as follows:  ‘agree’ =>[…]

Read More »

15 Essential CakePHP Tips

Note, this article was written a long time ago for CakePHP version 1.x … many of the points described here still apply in the latest 2.x versions of CakePHP. 1. Save() does not work! Sometimes it happens that save() fails without any obvious reason. Your data array looks fine and[…]

Read More »

Do I have any errors in my form?

A nice little trick to check if you have some errors in the view is to use the $session object. Try this (in the view): pr($this->validationErrors) or pr($session->validationErrors), be sure to actually have some errors in the form… I leave it up to you to come with some nice usage[…]

Read More »
%d bloggers like this: