This site uses cookies. By continuing, your consent is assumed. Learn more

124.9fm shares

Validating data in php cake

opinion

That has proven itself time and again in the last 9 months. Sometimes though, determining how to do something within a framework can be difficult.

The other day, I had a requirement for one of the applications for conditional data validation. CakePHP provides flexible and simple validation of your Model data that combined forms very complex rules.

Unfortunately, nothing out of the box handled conditional validation.

The validation package in CakePHP...

To be fair, there are some native options that may work for you in simple cases. Yet, setting anything at the Model rule level applies across all Controllers.

But we developers must support real world demands from clients. Anyway, there are also ways to validate from the controller.

But in practice, the code quickly becomes bloated. You begin to have calls to validate before every save. Even more for multi-model saveAll calls. You also have to list the Model fields to validate in the Controller. Too much coupling in my opinion.

News feed