我有以下代码,但根本无法使用。
在我看来,我有这个:
echo $this->Form->input('User.code', array(
'between' => '<div class="input-group">',
'after' => '</div>',
'label' => array('text' => 'Geschenkcode<span>*</span><br><div class="form-small">Geben Sie hier den Geschenkcode<br>aus dem DVD-Flyer an!</div>', 'class' => 'control-label'),
'div' => 'form-group',
'class' => 'form-control'
));
在我的模型中有以下内容:
class User extends AppModel {
public $validate = array(
'code' => array(
'isInCodes' => array(
'rule' => array('isInCodes'),
'message' => 'nenene'
)
),
);
public function isInCodes($code) {
return false;
}
}
控制器:
public function contest($slug = null) {
if (!$this->Contest->findBySlug($slug)) {
throw new NotFoundException(__('Invalid Contest'));
}
if ($this->request->is(array('post', 'put'))) {
if (!$this->User->validates()) {
$errors = $this->User->validationErrors;
debug($errors);
}
debug($this->request->data); exit();
return $this->redirect(array('action' => 'index'));
}
$this->Contest->recursive = 0;
$contest = $this->Contest->findBySlug($slug);
$this->set('contest', $contest);
}
这根本不起作用。验证运行就像不进入函数一样。有什么建议吗?
问候
答案 0 :(得分:2)
您需要在致电$this->User->set($this->request->data)
$this->User->validates()