Cakephp 2.x — Пользовательская проверка не работает

У меня есть следующий код, и он не работает вообще.

На мой взгляд, у меня есть это:

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);
}

Это не работает вообще. Проверка выполняется так, как будто она не входит в функцию. Какие-либо предложения?

С уважением

1

Решение

Вам нужно использовать $this->User->set($this->request->data) перед звонком $this->User->validates()

2

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector