bonjour,

petite question qui concerne la création d'interface pour des tables liées par une relation n-m, avec table de jointure au milieu

dans le formulaire (d'édition d'un élément) d'une des tables, j'ai mis un élément de type multi-checkbox avec dans le contrôleur un petit traitement qui va créer une donnée dans la table de jointure pour chaque case cochée

mon problème est que j'aimerai obliger l'utilisateur à faire au moins un choix (cocher au moins un truc)

j'ai essayé avec
Code : Sélectionner tout - Visualiser dans une fenêtre à part
$monElement->addValidator('NotEmpty');
mais sans effet

j'ai aussi essayé avec un validateur perso :
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
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
 
require_once 'Zend/Validate/Abstract.php';
require_once 'Zend/Validate/Exception.php';
 
class Fxc_Validate_ArraySize
extends Zend_Validate_Abstract
{
    const TOO_SHORT = 'arraySizeTooShort';
    const TOO_LONG  = 'arraySizeTooLong';
 
    /**
     * Nombre minimal d'éléments
     *
     * @var integer
     */
    protected $_min;
 
    /**
     * Nombre maximal d'éléments
     *
     * N'est pas pris en compte si null
     *
     * @var integer|null
     */
    protected $_max;
 
    protected $_messageVariables = array(
        'min' => '_min',
        'max' => '_max'
    );
 
    protected $_messageTemplates = array(
        self::TOO_SHORT => "array has less than %min% elements",
        self::TOO_LONG  => "array has more than %max% elements"
    );
 
    /**
     * Initialise les attributs
     *
     * @param  integer $min
     * @param  integer $max
     */
    public function __construct($min = 0, $max = null)
    {
        $this->setMin($min);
        $this->setMax($max);
    }
 
    public function getMin()
    {
        return $this->_min;
    }
 
    public function getMax()
    {
        return $this->_max;
    }
 
    public function setMin($min)
    {
        if (null !== $this->_max && $min > $this->_max) {
             throw new Zend_Validate_Exception('The minimum must be less than or equal to the maximum length, but ' . $min . ' > ' . $this->_max);
        }
        $this->_min = max(0, (integer) $min);
        return $this;
    }
 
    public function setMax($max)
    {
        if (null === $max) {
            $this->_max = null;
        } else if ($max < $this->_min) {
            throw new Zend_Validate_Exception('The maximum must be greater than or equal to the minimum length, but ' . $max . ' < ' . $this->_min);
        } else {
            $this->_max = (integer) $max;
        }
 
        return $this;
    }
 
    /**
     * Vérifie que le tableau $value a un nombre d'éléments compris entre les bornes min et max
     *
     * @param array $value
     * @return boolean
     */
    public function isValid($value)
    {
        $value = (array)$value;
        $this->_setValue($value);
 
        $size = count($value);
 
        if ($size < $this->_min) {
            $this->_error(self::TOO_SHORT);
        }
        if (null !== $this->_max && $this->_max < $size) {
            $this->_error(self::TOO_LONG);
        }
        if (count($this->_messages)) {
            return false;
        } else {
            return true;
        }
    }
}
mais le validateur est appliqué aux élément du tableau et pas au tableau lui-même

y a t il un moyen "propre" de faire cette vérif ?

merci par avance