cakephp/localized

Can I add a localized method?

Closed this issue · 1 comments

I have put the validation in the App \ Model \ validation path.
I have added the static method to the interface and method in the corresponding xxvalidation.

But when I try to use it:

$validator = new Validator();
        // add the provider to the validator
        $validator->provider('es', 'App\Model\Validation');
        // use the provider in a field validation rule
        $validator->add('username', 'username', [
            'rule' => 'username',
            'provider' => 'es',
			'message' => 'El nombre de usuario introducido no es válido'
        ])
		->isEmptyAllowed('username',false);
		;
        return $validator;

Give me the error Unable to call method "username" in "is" provider for field "username".
If I modify the original vendor / cakephp / localized class if that works correctly.
what can i do?

@DavidGonzalezGutierrez What is the exaxt class name incl. namespace of your class?
Looks like you just passed the namespace to the class, omitting the actual class name.

Tip: always use the new ::class syntax, this way the IDE will tell you if that one doesnt exist and will auto-include the use statement for you:

    use App\Model\Validation\EsValidation;

    $validator->provider('es', EsValidation::class);

See https://github.com/cakephp/localized#model-validation