Is there any possibility to use the gettext functionallity within the CakePHP model validation array?
Usually a programmer would do it like this:
class Data extends AppModel
{
var $validate = array(
'title' => array(
'NichtLeer' => array(
'rule' => array('between', 4, 20),
'allowEmpty' => false,
'message' => _('Bitte geben Sie einen Titel an!')
)
)
);
}
But since it is not possible to use functions outside a method's scope, I have to find another clean alternative.
So, is there any alternative to the one, that defines the validations improvise开发者_开发知识库d in the model's setup method?
Regards, Benedikt
Building the validate
array in the constructor could be considered a clean alternative:
class Data extends AppModel {
public function __construct() {
$this->validate = array(
'title' => array(
'NichtLeer' => array(
'rule' => array('between', 4, 20),
'allowEmpty' => false,
'message' => _('Bitte geben Sie einen Titel an!')
)
)
);
}
}
精彩评论