验证表单时出现_buildSchema错误

时间:2020-08-31 19:10:47

标签: php forms validation cakephp cakephp-3.0

大家晚上好, 我正在尝试验证Cake php下的表单,但是遇到以下错误:

致命错误:App \ Form \ ContactForm :: _ buildSchema(Cake \ Form \ Schema $ schema)声明必须与Cake \ Form \ Form :: _ buildSchema(Cake \ Form \ Schema $ schema)声明:Cake \ Form第11行的\ src \ Form \ ContactForm.php中的\ Schema

这是我的页面/src/Form/ContactForm.php的代码:

namespace App\Form;

use Cake\Form\Form;
use Cake\Form\Schema;
use Cake\Mailer\Email;
use Cake\Validation\Validator;

class ContactForm extends Form
{
    protected function _buildSchema(Schema $schema)
    {
        return $schema->addField('message', 'text')
            ->addField('name', 'string')
            ->addField('email', ['type' => 'string'])
            ->addField('subject', ['type' => 'string']);
    }
    enter code here
    protected function validationDefault(Validator $validator)
    {
        $validator->add('name', 'length', [
                'rule' => ['minLength', 10],
                'message' => 'A name is required' 
            ])->add('email', 'format', [
                'rule' => 'email',
                'message' => 'A valid email address is required',
            ]);

    //     return $validator;
    // }

    // protected function _execute(array $data)
    // {
    //     // Send an email.
    //     return true;
    // }

您是否知道它的来源?

0 个答案:

没有答案