Zend FR

Consultez la FAQ sur le ZF avant de poster une question

Vous n'êtes pas identifié.

#1 30-06-2011 11:00:49

Black-Mamba
Nouveau membre
Date d'inscription: 22-06-2011
Messages: 6

[Zend_Form_*][1.11.7] Decorator et namespace

Bonjour à tous,

Je dois gérer l'affichage des erreurs d'une manière particulière j'ai donc créé un Décorateur personnel (Black_Form_Decorator_Erreurs), lorsque je l'appel dans ma classe Form tout va bien :

Code:

class Structure_Form_UtilisateurAjout extends Zend_Form
{

    public function init()
    {
        $this->addPrefixPath('Black_Form_Decorator', 'Black/Form/Decorator', 'decorator');
        $this->setElementDecorators(array(
            'ViewHelper',
            array('Erreurs', array('elements' => array('start' => '<span %s>', 'end' => '</span>', 'separator' => ' - '), 'ignore' => array('types' => array('hash')))),
            array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'valeur')),
            array('Label', array('tag' => 'td', 'class' => 'libelle')),
            array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
        ));
        $this->setDecorators(array(
            'FormElements',
            array('HtmlTag', array('tag' => 'table', 'class' => 'modification')),
            'Form'
        ));


        $this->addElement('text', 'nom', array(
            'label'      => 'Nom :',
            'required'   => true,
            'validators' => array(
                array('validator' => 'StringLength', 'options' => array(4, 20))
                )
        ));
        // ...
    }
}

J'ai également créé une classe Form typique qui est chargée de factoriser un peu tout ça (Black_Form_Ajout), j'arrive bien à un faire hériter mon Form du départ :

Code:

class Structure_Form_UtilisateurAjout extends Black_Form_Ajout
{

    public function init()
    {
        //...
    }
}

Mon Form typique :

Code:

<?php

class Black_Form_Ajout extends Zend_Form
{

    public function __construct($options = '')
    {
        parent::__construct($options);
        $this->addElement('hash', 'csrf', array(
            'ignore' => true,
            'decorators' => array(),
            'disableLoadDefaultDecorators' => true
        ));


        $this->setMethod('post');
    }
}

Mais lorsque je combine les deux ça plante (avec ou sans le addPrefixPath) :

Code:

<?php

class Black_Form_Ajout extends Zend_Form
{

    public function __construct($options = '')
    {
        parent::__construct($options);
//        $this->addPrefixPath('Black_Form_Decorator', 'Black/Form/Decorator', 'decorator');
        $this->setElementDecorators(array(
            'ViewHelper',
            array('Erreurs', array('elements' => array('start' => '<span %s>', 'end' => '</span>', 'separator' => ' - '))),
            array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'valeur')),
            array('Label', array('tag' => 'td', 'class' => 'libelle')),
            array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
        ));
        $this->setDecorators(array(
            'FormElements',
            array('HtmlTag', array('tag' => 'table', 'class' => 'modification')),
            'Form'
        ));

        // Et une protection anti CSRF
        $this->addElement('hash', 'csrf', array(
            'ignore' => true,
            'decorators' => array(),
            'disableLoadDefaultDecorators' => true
        ));


        $this->setMethod('post');
    }
}

L'erreur :

Warning:  Exception caught by form: Plugin by name 'Erreurs' was not found in the registry; used paths:
Zend_Form_Decorator_: Zend/Form/Decorator/
Stack Trace:
#0 /var/www/library/Zend/Form/Element.php(1808): Zend_Loader_PluginLoader-&gt;load('Erreurs')
#1 /var/www/library/Zend/Form/Element.php(2188): Zend_Form_Element-&gt;_getDecorator('Erreurs', Array)
#2 /var/www/library/Zend/Form/Element.php(1961): Zend_Form_Element-&gt;_loadDecorator(Array, 'Erreurs')
#3 /var/www/library/Zend/Form/Element.php(2021): Zend_Form_Element-&gt;getDecorators()
#4 /var/www/library/Zend/Form/Decorator/FormElements.php(101): Zend_Form_Element-&gt;render()
#5 /var/www/library/Zend/Form.php(2908): Zend_Form_Decorator_FormElements-&gt;render('')
#6 /var/www/library/Zend/Form.php(2924): Zend_Form-&gt;render()
#7 /var/www/application/modules/structure/views/scripts/utilisateur/ajout.phtml(7): Zend_Form-&gt;__toString()
#8 /var/www/library/Zend/View.php(108): include('/var/www/applic...')
#9 /var/www/library/Zend/View/Abstract.php(888): Zend_View-&gt;_run('/var/www/applic. in /var/www/library/Zend/Form.php on line 2929

Avez-vous une idée d'om ça peut venir ?

Pour votre aide,
Par avance,
Merci

Hors ligne

 

Pied de page des forums

Propulsé par PunBB
© Copyright 2002–2005 Rickard Andersson
Traduction par punbb.fr

Graphisme réalisé par l'agence Rodolphe Eveilleau
Développement par Kitpages