내 유효성 검사기를 사용할 수 있으며 값의 수를 확인합니다. 나는 정확히 같은 목적으로 - multiselect에서 선택된 값의 최대 값과 최소값을 확인하는 데 사용되었습니다.
<?php
class App_Validate_ValuesNumber extends Zend_Validate_Abstract
{
const TOO_LESS = 'tooLess';
const TOO_MUCH = 'tooMuch';
protected $_type = null;
protected $_val = null;
/**
* @var array
*/
protected $_messageTemplates = array(
self::TOO_LESS => "At least %num% values required",
self::TOO_MUCH => "Not more then %num% required",
);
/**
* @var array
*/
protected $_messageVariables = array(
'num' => '_val'
);
/**
* Constructor for the integer validator
*
* @param string $type Comparison type, that should be used
* TOO_LESS means that value should be greater then items number
* TOO_MUCH means opposite
* @param int $val Value to compare items number with
*/
public function __construct($type, $val)
{
$this->_type = $type;
$this->_val = $val;
}
/**
* Defined by Zend_Validate_Interface
*
* Returns true if and only if $value is a valid integer
*
* @param string|integer $value
* @return boolean
*/
public function isValid($value)
{
// Value shoul dbe greated
if ($this->_type == self::TOO_LESS) {
if (count($value) < $this->_val) {
$this->_error(self::TOO_LESS);
return false;
}
}
// Value should be less
if ($this->_type == self::TOO_MUCH) {
if (count($value) > $this->_val) {
$this->_error(self::TOO_MUCH);
return false;
}
}
return true;
}
}
아마도 그룹으로 묶어서 빠르게 작성한 그룹의 유효성 검사기를 추가하십시오. 각 요소 대신 그룹과 함께 오류를 표시하십시오. – hakre