Category Archives: CakePHP

How to use multiple validation rule sets per model in cakephp

As default we have single var $validate rule set in the model class which is triggered on each save() method call while saving form data. This is quite logical and sufficient for single form fields to validate but what if we have another form with somewhat different fields which we want to post and validate? As an answer i know of three different approaches. Continue reading

Cakephp important facts you must know – Part 1

Mininal use of $uses variable to load models
CakePHP loads all models specified in var $uses array when a controller action is called. By loading a model cakephp creates the schema/structure of the table and also caches it for further use in the application.

Let say you specify four models in the var $uses. Now every time you call a controller action, all four models will be loaded irrespective of any of four being used by controller action or not. For example, Continue reading

Multiple validation rules for a single field in cakephp

Cakephp framework provides a strong model validation mechanism. Here is the quick overview of multiple validation rules applied to a single field.

Let say we are using “User.password” and “User.password2” fields to accept/confirm password while registering to a site. We have “password2” field which is supposed to contain non-empty characters as well as the same password entered in the “password” field. Continue reading

TinyMce and Captcha collide in my cakephp application

I was struck in a very strange problem today. I was using captcha component to create and set a captcha session and image for view section. Next is the snippet of create function which i used to load component. I will be pasting JcaptchaComponent source code at the end for anyone who may want to take a look into the matter more precisely (however i feel the componet itself should be quite innocent) Continue reading