ds3464 2017-06-07 21:04
浏览 40

Zend框架1.12验证器错误

I'm getting an error with the StringLength validator in Zend Framework 1.12. The error is:

plugin by name StringLength was not found in the registry;used paths:Zend_Validate_:Zend/Validate/

My form is:

<?php

class Application_Form_Public_Registrazione_Registra extends App_Form_Abstract
{

    //definisco la variabile per la connessione al database
    protected $_publicModel;

    public function init()
    {
        $this->_publicModel = new Application_Model_Public();
        $this->setMethod('post');
        $this->setName('registra');
        $this->setAction(''); //vuota in quanto si genera nel Controller

        //per la gestione degli elementi di tipo file
        $this->setAttrib('enctype', 'multipart/form-data');

        //elemento grafico relativo al nome
        $this->addElement('text', 'nome', array(
            'label'       => 'Nome',
            'filters'     => array('StringTrim'),
            'validators'  => array(array('StringLenght', true, array(3, 20))),
            'required'    => true,
            'description' => 'Inserisci il tuo nome',
            'decorators'  => $this->elementDecorators,
        ));

        //elemento grafico relativo al cognome
        $this->addElement('text', 'cognome', array(
            'label'       => 'Cognome',
            'filters'     => array('StringTrim'),
            'validators'  => array(array('StringLenght', true, array(3, 20))),
            'required'    => true,
            'description' => 'Inserisci il tuo cognome',
            'decorators'  => $this->elementDecorators,
        ));

        //elemento grafico relativo al sesso
        $this->addElement('select', 'sesso', array(
            'label'        => 'Sesso',
            'multiOptions' => array('1' => 'M', '0' => 'F'), //1=maschio, 0=femmina
            'decorators'   => $this->elementDecorators,
        ));

        //elemento grafico relativo all' etá
        $this->addElement('text', 'eta', array(
            'label'       => 'Etá',
            'filters'     => array('StringTrim'),
            'validators'  => array(array('StringLenght', false, array(3, 20))), //false perché non deve proseguire se non é soddisfatto
            'required'    => true,
            'description' => 'Inserisci il tuo cognome',
            'decorators'  => $this->elementDecorators,
        ));

        //elemento grafico relativo al numero di telefono
        $this->addElement('text', 'telefono', array(
            'label'       => 'Telefono',
            'filters'     => array('StringTrim'),
            'validators'  => array(array('StringLenght', false, array(3, 20))), //false perché non deve proseguire se non é soddisfatto
            'required'    => true,
            'description' => 'Inserisci il tuo numero di telefono',
            'decorators'  => $this->elementDecorators,
        ));

        //elemento grafico relativo all'indirizzo
        $this->addElement('text', 'indirizzo', array(
            'label'       => 'Indirizzo',
            'filters'     => array('StringTrim'),
            'validators'  => array(array('StringLenght', false, array(3, 20))), //false perché non deve proseguire se non é soddisfatto
            'required'    => true,
            'description' => 'Inserisci il tuo indirizzo',
            'decorators'  => $this->elementDecorators,
        ));

        //elemento grafico relativo alla cittá
        $this->addElement('text', 'citta', array(
            'label'       => 'Città',
            'filters'     => array('StringTrim'),
            'validators'  => array(array('StringLenght', false, array(3, 20))),
            'required'    => true,
            'description' => 'Inserisci la tua città',
            'decorators'  => $this->elementDecorators,
        ));

        // elemento grafico relativo alla email
        $this->addElement('text', 'email', array(
            'label'      => 'La tua Email',
            'required'   => true,
            'filters'    => array('StringTrim'),
            'decorators' => $this->elementDecorators,
            'validators' => array(
                'EmailAddress',
            )
        ));

        //elemento grafico relativo all'username
        $this->addElement('text', 'username', array(
            'label'       => 'Username',
            'filters'     => array('StringTrim'),
            'validators'  => array(array('StringLenght', true, array(3, 20))),
            'required'    => true,
            'description' => 'Inserisci il tuo username scelto',
            'decorators'  => $this->elementDecorators,
        ));

        //elemento grafico relativo alla password
        $this->addElement('text', 'password', array(
            'label'       => 'Password',
            'filters'     => array('StringTrim'),
            'validators'  => array(array('StringLenght', true, array(3, 20))),
            'required'    => true,
            'description' => 'Inserisci la tua password scelta',
            'decorators'  => $this->elementDecorators,
        ));

        //elemento grafico relativo alla foto profilo
        $this->addElement('file', 'foto', array(
            'label'       => 'Immagine',
            'destination' => APPLICATION_PATH . '/../public/images/fotoutenti',
            'validators'  => array(
                array('Count', false, 1),
                array('Size', false, 202400), //9 mb per l'img
                array('Extension', false, array('jpg', 'gif'))),
            'decorators'  => $this->fileDecorators,
        ));

        //elemento grafico relativo al bottone conferma
        $this->addElement('submit', 'registrati', array(
            'label'      => 'Conferma e Registrati',
            'decorators' => $this->buttonDecorators,
        ));

        //setto i decorators
        $this->setDecorators(array(
            'FormElements',
            array('HtmlTag', array('tag' => 'table', 'class' => 'zend_form')),
            array('Description', array('placement' => 'prepend', 'class' => 'formerror')),
            'Form'
        ));

    }
}

Thanks for help!

  • 写回答

1条回答 默认 最新

  • dsnd7200 2017-06-07 21:17
    关注

    I think you misspelled the StringLength validator name. You wrote: StringLenght, which really doesn't exists.

    评论

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算