Thursday, March 13, 2014

Re: V3.0 Custom validation messages

It could be a bug. I'm going to check that out in a bit. To avoid the strict warning you need:

use Cake\Validation\Validator;

class ArticlesTable extends Table {

public function validationDefault(Validator $validator) {
...

On Thursday, March 13, 2014 6:07:47 AM UTC+1, Dr. Tarique Sani wrote:
My AtriclesTable has 


public function validationDefault($validator) {
        $validator
            ->add('title', 'not-Empty', [
                'rule' => 'notEmpty',
                'message' => 'You need to provide a title',
            ])
            ->add('body', 'not-Empty', [
                'rule' => 'notEmpty',
                'message' => 'A body is required'
            ]);
        return $validator;
}

When I try to save an article entity the validation runs fine but I am only getting the default in the ArticleEntity 

'errors' => [
'title' => [
(int) 0 => 'This field cannot be left empty'
],
'body' => [
(int) 0 => 'This field cannot be left empty'
]
]

Additionally there is a warning 

Strict (2048): Declaration of App\Model\Table\ArticlesTable::validationDefault() should be compatible with Cake\ORM\Table::validationDefault(Cake\Validation\Validator $validator) [APP/Model/Table/ArticlesTable.php, line 7]

What additional steps are needed to fix this?

Cheers
Tarique

--
=============================================================
The Conference Schedule Creator : http://shdlr.com

PHP for E-Biz : http://sanisoft.com
=============================================================

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: