IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Zend Framework PHP Discussion :

[ZF 2.2.5] Decorator et tableau


Sujet :

Zend Framework PHP

  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Mai 2013
    Messages
    68
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2013
    Messages : 68
    Par défaut [ZF 2.2.5] Decorator et tableau
    Hello !
    Je suis en train de me battre avec les decorator. Et je suis en train de me faire exploser
    Plus sérieusement c'est super dur >_<
    Je voudrais mettre dans un tableau les éléments d'un formulaire.
    Genre sur un colonne j'ai les labels et sur la deuxième les textfields. Mais je vois vraiment pas comment faire ça... Je sais même pas quel décorator il faut prendre...
    Si c'est possible à faire, y a t'il moyen de m'aiguiller ? Et si c'est pas possible, bah dite le moi quand même ^^

    Merci !

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Mai 2013
    Messages
    68
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2013
    Messages : 68
    Par défaut
    Ok J'ai trouvé alors je vais répondre ici pour ceux qui voudrait.
    D'abord Zend Framework 2 ne fonctionne pas avec les decorator alors c'est pas la peine de chercher dans cette direction. Je vais vous faire un exemple pour expliquer ça va être plus simple à comprendre :
    J'ai d'abord commencé par créer mon formulaire, rien de plus simple :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    public function __construct($name = null)
         {
             // we want to ignore the name passed
             parent::__construct('film');
     
             $this->add(array(
                 'name' => 'id',
                 'type' => 'Hidden',
             ));
             $this->add(array(
                 'name' => 'titre',
                 'type' => 'Text',
                 'options' => array(
                     'label' => 'Titre : ',
                 ),
             ));
             $this->add(array(
                 'name' => 'duree',
                 'type' => 'Number',
                 'options' => array(
                     'label' => 'Duree (minutes) : ',
                 ),
             ));
    		 $this->add(array(
                'type' => 'Zend\Form\Element\Select',
                'name' => 'vu',
                'options' => array(
                    'label' => 'Vu : ',
                    'value_options' => array(
                        'Oui' => 'Oui',
                        'Non' => 'Non',
                    ),
                ),
            ));
    		 $this->add(array(
                'type' => 'Zend\Form\Element\Select',
                'name' => 'support',
                'options' => array(
                    'label' => 'Support : ',
                    'value_options' => array(
                        'DVD' => 'DVD',
                        'BlueRay' => 'BlueRay',
    					'VHS' => 'VHS',
    					'DVDrip' => 'DVDrip',
    					'BDrip' => 'BDrip',
                    ),
                ),
            ));
             $this->add(array(
                 'name' => 'submit',
                 'type' => 'Submit',
                 'attributes' => array(
                     'value' => 'Go',
                     'id' => 'submitbutton',
                 ),
             ));
         }
    On voit que je récupère un String, un Integer et deux select comme ça y'a de la diversité
    Ensuite je déclare mes filtre pour pas me faire hacker :O
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    public function getInputFilter()
         {
             if (!$this->inputFilter) {
                 $inputFilter = new InputFilter();
     
                 $inputFilter->add(array(
                     'name'     => 'id',
                     'required' => true,
                     'filters'  => array(
                         array('name' => 'Int'),
                     ),
                 ));
     
                 $inputFilter->add(array(
                     'name'     => 'titre',
                     'required' => true,
                     'filters'  => array(
                         array('name' => 'StripTags'),
                         array('name' => 'StringTrim'),
                     ),
                     'validators' => array(
                         array(
                             'name'    => 'StringLength',
                             'options' => array(
                                 'encoding' => 'UTF-8',
                                 'min'      => 1,
                                 'max'      => 100,
                             ),
                         ),
                     ),
                 ));
     
                 $inputFilter->add(array(
                     'name'     => 'duree',
                     'required' => true,
                     'filters'  => array(
                         array('name' => 'StripTags'),
                         array('name' => 'StringTrim'),
                     ),
                     'validators' => array(
                         array(
                             'name'    => 'StringLength',
                             'options' => array(
                                 'encoding' => 'UTF-8',
                                 'min'      => 1,
                                 'max'      => 100,
                             ),
                         ),
                     ),
                 ));
     
    			 $inputFilter->add(array(
                     'name'     => 'vu',
                     'required' => true,
                     'filters'  => array(
                         array('name' => 'StripTags'),
                         array('name' => 'StringTrim'),
                     ),
                     'validators' => array(
                         array(
                             'name'    => 'StringLength',
                             'options' => array(
                                 'encoding' => 'UTF-8',
                                 'min'      => 1,
                                 'max'      => 50,
                             ),
                         ),
                     ),
                 ));
     
    			 $inputFilter->add(array(
                     'name'     => 'support',
                     'required' => true,
                     'filters'  => array(
                         array('name' => 'StripTags'),
                         array('name' => 'StringTrim'),
                     ),
                     'validators' => array(
                         array(
                             'name'    => 'StringLength',
                             'options' => array(
                                 'encoding' => 'UTF-8',
                                 'min'      => 1,
                                 'max'      => 50,
                             ),
                         ),
                     ),
                 ));
     
                 $this->inputFilter = $inputFilter;
             }
     
             return $this->inputFilter;
         }
    Et finalement je crée mon script add.phtml qui va me fair eun jolie affichage. Et la magie elle est là ! On peut décomposer les éléments de son formulaire avec formLabel pour le label, formInput pour le textfield (formNumber pour integer et formSelect pour les select ) et formElementErreur pour afficher les éventuelles erreurs. Moi j'ai fait une colonne label, une colonne input (number, select) et une colonne erreur.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    <?php
     
    $title = 'Add new film';
    $this->headTitle($title);
    ?>
    <h1><?php echo $this->escapeHtml($title); ?></h1>
    <?php
    $form->setAttribute('action', $this->url('film', array('action' => 'add')));
    $form->prepare();
     
     
    echo $this->form()->openTag($form);
    echo $this->formHidden($form->get('id')); ?>
    <table class="zend_form">
    <tr><td>
    <?php echo $this->formLabel($form->get('titre')); ?>
    </td>
    <td>
    <?php echo $this->formInput($form->get('titre')); ?>
    </td>
    <td>
    <?php echo $this->formElementErrors($form->get('titre')); ?>
    </td></tr>
    <tr><td>
    <?php echo $this->formLabel($form->get('duree')); ?>
    </td>
    <td>
    <?php echo $this->formNumber($form->get('duree')); ?>
    </td>
    <td>
    <?php echo $this->formElementErrors($form->get('duree')); ?>
    </td></tr>
    <tr><td>
    <?php echo $this->formLabel($form->get('vu')); ?>
    </td>
    <td>
    <?php echo $this->formSelect($form->get('vu')); ?>
    </td>
    <td>
    <?php echo $this->formElementErrors($form->get('vu')); ?>
    </td></tr>
    <tr><td>
    <?php echo $this->formLabel($form->get('support')); ?>
    </td>
    <td>
    <?php echo $this->formSelect($form->get('support')); ?>
    </td>
    <td>
    <?php echo $this->formElementErrors($form->get('support')); ?>
    </td></tr>
    <tr><td>
    </td>
    <td>
    <?php echo $this->formSubmit($form->get('submit')); ?>
    </td>
    <td>
    </td></tr>
    </table>
    <?php echo $this->form()->closeTag(); ?>
    Et voilà j'ai un joli formulaire bien aligné !

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. decorators: ID d'une ligne d'un tableau
    Par bedford dans le forum Zend Framework
    Réponses: 1
    Dernier message: 23/06/2011, 14h18
  2. Réponses: 2
    Dernier message: 27/05/2002, 19h46
  3. verification de doublons dans un tableau
    Par bohemianvirtual dans le forum C
    Réponses: 11
    Dernier message: 25/05/2002, 12h21
  4. transmision de tableau en parametre
    Par Horus dans le forum C++Builder
    Réponses: 3
    Dernier message: 16/05/2002, 11h15
  5. Réponses: 4
    Dernier message: 13/05/2002, 16h43

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo