проверка cakePHP - PullRequest
       10

проверка cakePHP

4 голосов
/ 26 октября 2009

Я работаю над проектом cakePHP и настроил проверку данных. У меня проблема в том, что я получаю ошибку от ядра / модели cakePHP.

Ошибка: Примечание (8): неопределенное смещение: 0 [CORE / cake / libs / model / model.php, строка 2435]

                        if (is_array($validator['rule'])) {
                        $rule = $validator['rule'][0];

Мои правила проверки выглядят так:

    var $validate = array(
    'name' => array(
        'rule' => array('maxLength' => 80),
        'required' => true,
        'message' => 'Please enter your name'
    ),
    'address1' =>  array(
        'rule' => array('maxLength' => 80),
        'required' => true,
        'message' => 'You forgot your address'
    ),
    'address2' =>  array(
        'rule' => array('maxLength' => 80),
        'message' => 'Your address can\'t be that long?'
    ),
    'city' =>  array(
        'rule' => array('maxLength' => 80),
        'required' => true,
        'message' => 'Your city can\'t be that long?'
    ),
    'zip' =>  array(
        'rule' => array('postal', null, 'us'),
        'required' => true,
        'message' => 'Your zip code is not in the corect format.'
    ),
    'phone' =>  array(
        'rule' => array('phone', null, 'us'),
        'required' => true,
        'message' => 'Your phone number is not in the corect format.'
    ),
    'email' => array(
        'rule' => 'email',
        'required' => true,
        'message' => 'Please enter a valid email address.'
    ),
    'seats' =>  array(
        'rule' => 'numeric',
        'required' => true,
        'message' => 'You forgot to let us know how many seats you need.  If you will not be attending please enter a zero (0)'
    ),
    'seat_with' => array(   
        'rule' => array('maxLength' => 80),
        'message' => 'Please keep this field below 80 charcters.'
    ),
    'cc_name' =>  array(
        'rule' => array('maxLength' => 80),
        'required' => true,
        'message' => 'Did you forget something?'
    ),
    'cc_number' => array(
        'rule' => array('cc', 'all', false, null),
        'required' => true,
        'message' => 'Your credit card number is not in the correct format.'
    ),
    'cc_expiration' => array(
        'rule' => array('date', 'my'),
        'required' => true,
        'message' => 'The correct answer will be in the following format MM/YYYY'
    ),
    'cc_cvv' => array(
        'rule' => 'numeric',
        'required' => true,
        'message' => 'Numbers only please.'
    )
    );

Любая помощь очень ценится.

1 Ответ

9 голосов
/ 26 октября 2009

Ваша проблема в синтаксисе правила:

array('maxLength' => 80)

Как и другие ваши правила, это ,, а не =>: array('maxLength', 80).


Кстати, мой город может быть таким длинным: http://en.wikipedia.org/wiki/Krung Тхеп Маханахон Амон Раттанакосин Махинтхара ... ; -)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...