The Set-up: CakePHP 1.2 and MySQL database tables created.

After a freshly baked application, what's next?
The database and MVC's are done. Next is to tweak the generated code from bake.


Enums

enum fields in the database (.., enum('Gold','Silver','No Color')..) won't appear as normally as select fields ( ) in the views by default.
In the bakery, Baked Enums by John Zimmerman shows how enums can be retrieved from their corresponding field values.
Also with enums, Ron Chaplin's Dynamic CSS for CSS and More! is another good example of a ~wee bit overloaded cakephp with enums.



Alphanumerics with Spaces

After setting the validation rules for a field as alphanumeric, say, in a field like firstName or organization, a value for that field may be similar to Juan Dela, or Bahay Kubo respectively. To allow alphanumerics with spaces, i found a discussion with a post by Marcin Jaworski-2 at Nabble as a solution. He replaced the existing validation rule with a regular expression rule:


Before:

var $validate = array(
'firstname' => array('_extract')
);

After:

var $validate = array(
'firstname' => array('rule' => array('custom', '/^[a-z0-9 ]*$/i'))
);

0 comments:

Newer Post Older Post Home