當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Zend_Validate_NotEmpty::setTranslator方法代碼示例

本文整理匯總了PHP中Zend_Validate_NotEmpty::setTranslator方法的典型用法代碼示例。如果您正苦於以下問題:PHP Zend_Validate_NotEmpty::setTranslator方法的具體用法?PHP Zend_Validate_NotEmpty::setTranslator怎麽用?PHP Zend_Validate_NotEmpty::setTranslator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zend_Validate_NotEmpty的用法示例。


在下文中一共展示了Zend_Validate_NotEmpty::setTranslator方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: validate

 /**
  * Checks all form rules
  *
  * @return null
  */
 public function validate()
 {
     $attribs = $this->formHandler->getAttributes();
     foreach ($attribs as $key => $attributes) {
         if (!array_key_exists($key, $attribs)) {
             throw new Exception("The field '{$key}' does not exists!");
         }
         $label = array_key_exists('label', array_keys($this->options)) ? $attributes["label"] : $key;
         $all_attribs = array();
         foreach ($attributes as $attr) {
             $all_attribs[$attr->getName()] = $attr->getValue();
         }
         foreach ($attributes as $name => $attr) {
             $name = $attr->getName();
             $value = $attr->getValue();
             $attrib = $this->formHandler->getAttribute($label, "value");
             $form_value = !is_null($attrib) ? $attrib->getValue() : null;
             switch ($name) {
                 case 'required':
                     $validator = new Zend_Validate_NotEmpty();
                     break;
                 case 'minlength':
                     $validator = new Zend_Validate_StringLength(array('min' => $value));
                     break;
                 case 'maxlength':
                     $validator = new Zend_Validate_StringLength(array('max' => $value));
                     break;
                 case 'type':
                     switch ($value) {
                         case 'number':
                             $validator = new Zend_Validate_Digits();
                             break;
                         case 'email':
                             $validator = new Zend_Validate_EmailAddress();
                             break;
                         case 'date':
                             $validator = new Zend_Validate_Date();
                             break;
                         case 'url':
                             $validator = new Drone_Validate_Uri();
                             break;
                     }
                     break;
                 case 'min':
                     if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], array('number', 'range'))) {
                         $validator = new Drone_Validate_GreaterThan(array('min' => $value, 'inclusive' => true));
                     } else {
                         throw new Exception("The input type must be 'range' or 'number'");
                     }
                     break;
                 case 'max':
                     if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], array('number', 'range'))) {
                         $validator = new Drone_Validate_LessThan(array('max' => $value, 'inclusive' => true));
                     } else {
                         throw new Exception("The input type must be 'range' or 'number'");
                     }
                     break;
                 case 'step':
                     $baseValue = array_key_exists('min', $all_attribs) ? $all_attribs['min'] : 0;
                     if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], array('range'))) {
                         $validator = new Drone_Validate_Step(array('baseValue' => $baseValue, 'step' => $value));
                     } else {
                         throw new Exception("The input type must be 'range'");
                     }
                     break;
             }
             if (in_array($name, array('required', 'digits', 'minlength', 'maxlength', 'type', 'min', 'max', 'date', 'step'))) {
                 $validator->setTranslator($this->translator);
                 if (gettype($form_value) == 'array') {
                     foreach ($form_value as $val) {
                         $valid = $validator->isValid($val);
                         $this->setValid($valid);
                         if (!$valid) {
                             if (!in_array($key, array_keys($this->messages))) {
                                 $this->messages[$key] = array();
                             }
                             $this->messages[$key] = array_merge($this->messages[$key], $validator->getMessages());
                         }
                     }
                 } else {
                     $valid = $validator->isValid($form_value);
                     $this->setValid($valid);
                     if (!$valid) {
                         if (!in_array($key, array_keys($this->messages))) {
                             $this->messages[$key] = array();
                         }
                         $this->messages[$key] = array_merge($this->messages[$key], $validator->getMessages());
                     }
                 }
             }
         }
     }
     foreach ($this->options as $key => $options) {
         if (isset($options["validators"]) and is_array($options["validators"])) {
             $attrib = $this->formHandler->getAttribute($key, "required");
//.........這裏部分代碼省略.........
開發者ID:fermius,項目名稱:Drone,代碼行數:101,代碼來源:Drone_Validator_FormValidator.php


注:本文中的Zend_Validate_NotEmpty::setTranslator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。