只有当模型中不存在新消息时,我才能成功地将新消息放入视图文件中。我的意思是验证必须在模型中,但附加到这些验证的消息不应该在那里。
示例模型
public $validate = array(
'username' => array(
'required' => array(
'rule' => array('notEmpty'),
'required' => true, 'allowEmpty' => false,
'message' => 'Please enter a username.'),
'alpha' => array(
'rule' => array('alphaNumeric'),
'message' => 'The username must be alphanumeric.'),
'unique_username' => array(
'rule'=>array('isUnique', 'username'),
'message' => 'This username is already in use.'),
'username_min' => array(
'rule' => array('minLength', '3'),
'message' => 'The username must have at least 3 characters.')),
'email' => array(
...................
...................
这是一个视图示例
echo $this->Form->input('username',array(
'label' => __d('app_users','Username'),
'error' => array(
'required' => __d('app_users', 'Please enter a username'),
.....................
.....................
));
所以,我的问题是如何在不移除'message' => 'Please enter a username.'
模型的情况下将其变成作品,而是真正覆盖它。