Cakephp 2.x-自定义验证不起作用
我有以下代码,它根本不工作 在我看来,我有这样的想法:Cakephp 2.x-自定义验证不起作用,php,validation,cakephp,cakephp-2.0,cakephp-model,Php,Validation,Cakephp,Cakephp 2.0,Cakephp Model,我有以下代码,它根本不工作 在我看来,我有这样的想法: echo $this->Form->input('User.code', array( 'between' => '<div class="input-group">', 'after' => '</div>', 'label' => array('text' => 'Geschenkcode<span&
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'
));
控制器:
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);
}
这根本不起作用。验证会像不进入函数一样运行。有什么建议吗
关于在调用
$this->User->validates()之前,您需要使用$this->User->set($this->request->data)
,同时显示控制器代码。我更新了帖子。。。
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);
}