当前位置: 首页>>代码示例>>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;未经允许,请勿转载。