Zend FR

Consultez la FAQ sur le ZF avant de poster une question

Vous n'êtes pas identifié.

#1 04-01-2009 23:00:04

yannux
Membre
Lieu: Rennes
Date d'inscription: 07-04-2007
Messages: 284
Site web

Etendre Zend_Form et Zend_Form_Subform

J'ai étendu Zend_Form et Subform pour rédéfinir mes décorateurs, tout a bien pour les éléments dans un form et dans un displaygroup. Mais dans un subform ça me garde les dt dd  sad.

Code:

<?php
class Dis_Form extends Zend_Form
{

    public function loadDefaultDecorators()
    {
        $this->setDecorators(array(
            'FormElements',
            'Form',
        ));

        //Set decorators for the displaygroup:
        $this->setDisplayGroupDecorators(array(
            'FormElements',
            array(array('ulwrap' => 'HtmlTag'), array('tag' => 'ul')), //this adds a <ul> inside the <form>
            'Fieldset',
        ));

        //Set the decorators we need:
        $this->setElementDecorators(array(
            'ViewHelper',
            'Label',
            'Errors',
            new Zend_Form_Decorator_HtmlTag(array('tag' => 'li')) //wrap elements in <li>'s
        ));

        $this->setSubFormDecorators(array(
            'FormElements',
            array(array('ulwrap' => 'HtmlTag'), array('tag' => 'ul')), //this adds a <ul> inside the <form>
            'Fieldset',
        ));

        $elements = $this->getElements();
        foreach ($elements as $element) {
            if($element instanceof Zend_Form_Element_Submit) {
                $element ->setDecorators(array(
                    'ViewHelper',
                    new Zend_Form_Decorator_HtmlTag(array('tag' => 'li')) //wrap elements in <li>'s
                ));
            }
        }
    }
}

Code:

<?php
class Dis_Form_SubForm extends Dis_Form
{
    public function loadDefaultDecorators()
    {
        $this->setElementDecorators(array(
            'ViewHelper',
            'Label',
            'Errors',
            new Zend_Form_Decorator_HtmlTag(array('tag' => 'li')) //wrap elements in <li>'s
        ));
    }
}

Même si je ne définis pas   public function loadDefaultDecorators() pour Dis_Form_Subform  j'ai le même résultat.

Quelqu'un a une idée ? :s


Société : Direct Info Service

Hors ligne

 

#2 05-01-2009 11:32:23

yannux
Membre
Lieu: Rennes
Date d'inscription: 07-04-2007
Messages: 284
Site web

Re: Etendre Zend_Form et Zend_Form_Subform

Petite réponse à moi même si ça peut en aider, il faut également redéfinir la méthode render() apperement :

Code:

    public function render(Zend_View_Interface $view = null)
    {
        $this->setSubFormDecorators(array(
            'FormElements',
            array(array('ulwrap' => 'HtmlTag'), array('tag' => 'ul')), //this adds a <ul> inside the <form>
            'Fieldset',
        ));

        // walk subforms recursively using stack and set decorators to them
        $stack = array($this);
        while (!empty($stack)) {
            $form = array_pop($stack);
            //Set decorators for the displaygroup:
            $form->setDisplayGroupDecorators(array(
                'FormElements',
                array(array('ulwrap' => 'HtmlTag'), array('tag' => 'ul')), //this adds a <ul> inside the <form>
                'Fieldset',
            ));

            //Set the decorators we need:
            $form->setElementDecorators(array(
                'ViewHelper',
                'Label',
                'Errors',
                new Zend_Form_Decorator_HtmlTag(array('tag' => 'li')) //wrap elements in <li>'s
            ));

            foreach ($form->getSubForms() as $subForm) {
                $stack[] = $subForm;
            }
        }

        return parent::render($view);
    }

Société : Direct Info Service

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