I prefer overloading the __construct method. So I get something like this <?php
class Category extends AppModel { var $name = 'Category'; var $useTable = 'categories'; //override construct method for translation function __construct($id = false, $table = null, $ds = null) { parent::__construct($id, $table, $ds); $this->validate = array( 'name' => array( 'isrequired' => array('rule' => array('minLength', 1), 'message' => __('Required field', true)), 'haslength' => array( 'rule' => array('maxLength', 50), 'message' => sprintf(__('Maximum length is %d characters', true), 50)) ), 'filename' => array( 'isrequired' => array('rule' => array('minLength', 1), 'message' => __('Required field', true), 'haslength' => array( 'rule' => array('maxLength', 255), 'message' => sprintf(__('Maximum length is %d characters', true), 255)) ), 'filesize' => array( 'isrequired' => array('rule' => array('minLength', 1), 'message' => __('Required field', true)) ) ); } } ?> <?php class Category extends AppModel { var $name = 'Category'; var $useTable = 'categories'; //override construct method for translation function __construct($id = false, $table = null, $ds = null) { parent::__construct($id, $table, $ds); $this->validate = array( 'name' => array( 'isrequired' => array('rule' => array('minLength', 1), 'message' => __('Required field', true)), 'haslength' => array( 'rule' => array('maxLength', 50), 'message' => sprintf(__('Maximum length is %d characters', true), 50)) ), 'filename' => array( 'isrequired' => array('rule' => array('minLength', 1), 'message' => __('Required field', true), 'haslength' => array( 'rule' => array('maxLength', 255), 'message' => sprintf(__('Maximum length is %d characters', true), 255)) ), 'filesize' => array( 'isrequired' => array('rule' => array('minLength', 1), 'message' => __('Required field', true)) ) ); } } ?> On Jan 31, 8:26 pm, Sliv <[EMAIL PROTECTED]> wrote: > I just ran into this issue and did some digging: > > Here's francky06l's ticket:https://trac.cakephp.org/ticket/3318 > > It appears it was fixed in changeset 5815 but then the change was > reverted in changeset 5827:https://trac.cakephp.org/changeset/5827 > > Does anyone know why this change was reverted and what the recommended > solution is now? > > On Dec 5 2007, 4:12 am, francky06l <[EMAIL PROTECTED]> wrote: > > > You can't use it in validation rules (I suppose for the message) ... > > I have actually done it for the validation, but for this made my own > > invalidate method in app_model.php as follow : > > > function invalidate($field, $value = null) > > { > > if (!is_array($this->validationErrors)) > > { > > $this->validationErrors = array(); > > } > > > if(empty($value)) > > { > > $value = true; > > } > > $this->validationErrors[$field] = __($value, true); > > } > > > The changes to the core function is the last line. Then you can set > > the "msgid" in the validation rules. > > I submitted a ticket to have this modification, but seems it has not > > been introduced yet. > > Hope this helps > > > On Dec 5, 12:31 am, cakeFreak <[EMAIL PROTECTED]> wrote: > > > > Well sorry, this works in controllers. > > > > I had problems using it in a validation rule inside models. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---