PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, February 22, 2022

[FIXED] CakePHP 3 validator - Unable to call method “” in “default” provider for upload field

 February 22, 2022     cakephp, cakephp-3.0, php     No comments   

Issue

Here is my validator for the field article where pdf files should be uploaded:

 $validator
->add('article', [
    'rule' => [
        'extension' => [
            ['article', 'pdf'],
            'message' => 'Only  pdf!'
        ]
    ]
])
->notEmpty('article');

This gives an error:

"Unable to call method "" in "default" provider for field "article""

How can I fix this to enable uploading only pdf files to the field article?


Solution

The order of the elements in your code is wrong.

Also worth a look: API Class Validation - Extension

$validator
  ->add('article', [
    'extension' => [
      'rule' => [ 'extension', ['pdf'] ],
      'message' => 'Only PDF!'
    ]
  ])
  ->notEmpty('article', 'This field is required')
  ;

You should also check the mimeType to enhance security. Works similar, see also the example in the book in the chapter conditional validation



Answered By - Oops D'oh
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing