当前位置: 首页>>代码示例>>PHP>>正文


PHP Validation::rules方法代码示例

本文整理汇总了PHP中Validation::rules方法的典型用法代码示例。如果您正苦于以下问题:PHP Validation::rules方法的具体用法?PHP Validation::rules怎么用?PHP Validation::rules使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Validation的用法示例。


在下文中一共展示了Validation::rules方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _validation

 /**
  * Initializes validation rules, and labels
  *
  * @return void
  */
 protected function _validation()
 {
     // Build the validation object with its rules
     $this->_validation = Validation::factory($this->_object)->bind(':model', $this)->bind(':original_values', $this->_original_values)->bind(':changed', $this->_changed);
     foreach ($this->rules() as $field => $rules) {
         $this->_validation->rules($field, $rules);
     }
     // Use column names by default for labels
     $columns = array_keys($this->_table_columns);
     // Merge user-defined labels
     $labels = array_merge(array_combine($columns, $columns), $this->labels());
     foreach ($labels as $field => $label) {
         $this->_validation->label($field, $label);
     }
 }
开发者ID:ultimateprogramer,项目名称:cms,代码行数:20,代码来源:orm.php

示例2: _add_rules

 /**
  * Add rules to the validation object
  *
  * @access protected
  * @param mixed Formo_Container $field. (default: NULL)
  * @return void
  */
 protected function _add_rules(Validation $validation)
 {
     if (!($rules = $this->get('rules'))) {
         // Only do anything if the field has rules
         return;
     }
     $validation->label($this->alias(), $this->view()->label());
     $validation->rules($this->alias(), $rules);
 }
开发者ID:kanikaN,项目名称:qload,代码行数:16,代码来源:validator.php

示例3: onValidateDocument

 /**
  * 
  * @param Validation $validation
  * @param DataSource_Hybrid_Document $doc
  * @return Validation
  */
 public function onValidateDocument(Validation $validation, DataSource_Hybrid_Document $doc)
 {
     $file = NULL;
     $types = $this->types;
     if ($validation->offsetExists($this->name)) {
         $file = $validation->offsetGet($this->name);
     }
     if ($this->isreq === TRUE) {
         if (is_array($file)) {
             $validation->rules($this->name, array(array('Upload::not_empty')));
         } else {
             $validation->rules($this->name, array(array('not_empty')));
         }
     }
     if (is_array($file)) {
         $validation->rule($this->name, 'Upload::valid')->rule($this->name, 'Upload::size', array(':value', $this->max_size));
         if (!empty($types)) {
             $validation->rule($this->name, 'Upload::type', array(':value', $this->types));
         }
     }
     return parent::onValidateDocument($validation, $doc);
 }
开发者ID:ZerGabriel,项目名称:cms-1,代码行数:28,代码来源:file.php

示例4: _add_rules_to_validation

 /**
  * Add rules to a validation object.
  *
  * @access protected
  * @param Validation $validation
  * @return void
  */
 protected function _add_rules_to_validation(Validation $validation)
 {
     $validation->rules($this->alias(), $this->_rules);
 }
开发者ID:bmidget,项目名称:kohana-formo,代码行数:11,代码来源:Innards.php

示例5: _check

 /**
  * Add validation rules to validation object
  *
  * @param  Validation  Validation object
  * @return array
  */
 protected function _check(Validation $data)
 {
     foreach ($this->_fields as $name => $field) {
         if ($field['type'] === 'email') {
             $data->rule($name, 'email');
         }
         if (Arr::get($field, 'required')) {
             $data->rule($name, 'required');
         }
         if (Arr::get($field, 'unique')) {
             $data->rule($name, array(':model', '_is_unique'), array(':validation', $name));
         }
         foreach (array('min_value', 'max_value', 'min_length', 'max_length') as $rule) {
             if (Arr::get($field, $rule) !== NULL) {
                 $data->rule($name, $rule, array(':value', $field[$rule]));
             }
         }
         if (isset($field['rules'])) {
             $data->rules($name, $field['rules']);
         }
         if (isset($field['label'])) {
             $data->label($name, $field['label']);
         }
     }
     return $data;
 }
开发者ID:tscms,项目名称:mangodb,代码行数:32,代码来源:Mango.php

示例6: onValidateDocument

 /**
  * 
  * @param Validation $validation
  * @param DataSource_Hybrid_Document $doc
  * @return Validation
  */
 public function onValidateDocument(Validation $validation, DataSource_Hybrid_Document $doc)
 {
     $image = $doc->get($this->name);
     $url = $doc->get($this->name . '_url');
     $from_url = FALSE;
     if (Valid::url($url)) {
         $from_url = TRUE;
     }
     if ($this->isreq === TRUE and $from_url === FALSE) {
         if (is_array($image)) {
             $validation->rules($this->name, array(array('Upload::not_empty')));
         } else {
             $validation->rules($this->name, array(array('not_empty')));
         }
     } elseif ($this->isreq === TRUE and $from_url === TRUE) {
         $validation->rules($this->name . '_url', array(array('not_empty')));
     }
     if ($from_url === FALSE and is_array($image)) {
         $validation->rules($this->name, array(array('Upload::valid'), array('Upload::type', array(':value', $this->types)), array('Upload::size', array(':value', $this->max_size))));
     } else {
         if ($from_url === TRUE) {
             $ext = strtolower(pathinfo($url, PATHINFO_EXTENSION));
             $validation->rules($this->name . '_url', array(array('url'), array('in_array', array($ext, $this->types))));
         }
     }
     return $validation->label($this->name . '_url', $this->header)->label($this->name, $this->header);
 }
开发者ID:ZerGabriel,项目名称:cms-1,代码行数:33,代码来源:image.php

示例7: action_import

 public function action_import()
 {
     $pass_id = -1;
     $import_success = array();
     //Store reg_id's that were successfully imported.
     $import_failure = array();
     //Store reg_id's that were not imported (error).
     $reg_ids = array();
     if ($post = $this->request->post()) {
         $validate = new Validation($_FILES);
         $validate->rules('csv_file', array(array('Upload::not_empty', NULL), array('Upload::valid', NULL), array('Upload::size', array(':value', '1M')), array('Upload::type', array(':value', array('csv')))));
         $pass_id = empty($post['pass_id']) ? -1 : $post['pass_id'];
         $pass = $this->loadPass($post);
         if ($validate->check() && isset($_FILES['csv_file']) && $pass) {
             $handle = fopen($_FILES['csv_file']['tmp_name'], 'rb');
             $line = fgetcsv($handle);
             while ($line = fgetcsv($handle)) {
                 $line[0] = trim($line[0]);
                 //In the event of a blank row, there is only one element.
                 if (empty($line[0])) {
                     continue;
                 }
                 $reg = $this->generateReg($pass, $line);
                 if (!$reg->pickupStatus) {
                     $reg->pickupStatus = 0;
                 }
                 $values = array('email' => $reg->email, 'phone' => $reg->phone);
                 try {
                     if ($reg->reserveTickets()) {
                         $reg->save($this->validateEmailOrPhone($values));
                         if (!isset($import_success[$reg->email])) {
                             $import_success[$reg->email] = array();
                         }
                         array_push($import_success[$reg->email], $reg);
                         $reg->finalizeTickets();
                         if (@$_POST['email_on_completion']) {
                             array_push($reg_ids, $reg->id);
                         }
                     } else {
                         array_push($import_failure, array('reg' => $reg, 'errors' => array('No more tickets available.')));
                     }
                 } catch (ORM_Validation_Exception $e) {
                     $reg->releaseTickets();
                     array_push($import_failure, array('reg' => $reg, 'errors' => $e->errors('')));
                 }
             }
             fclose($handle);
             /* FIXME: Send an email per index. */
         } else {
             if (!$pass) {
                 $this->addError('Not a valid ticket! Please select a valid ticket.');
             } else {
                 $this->addError('Not a valid file. Please try again.');
             }
         }
     }
     if (!empty($import_success) || !empty($import_failure)) {
         $this->template->content = new View('admin/UploadResults', array('import_success' => $import_success, 'import_failure' => $import_failure));
         if (!empty($reg_ids) && @$_POST['email_on_completion']) {
             $config = Kohana::config('ecmproject');
             $email = Email::factory($config['registration_subject']);
             $email->from($config['outgoing_email_address'], $config['outgoing_email_name']);
             $regs = ORM::Factory('Registration')->where('registrations.id', 'IN', $reg_ids)->with('convention')->where('email', '!=', '')->order_by('email')->find_all();
             $email = '';
             $data = array();
             foreach ($regs as $reg) {
                 if ($email != $reg->email) {
                     if (count($data)) {
                         $this->email_imported_regs($email, $data);
                     }
                     $data = array();
                 }
                 $email = $reg->email;
                 $data['registrations'][$reg->convention->name][] = $reg;
                 $data['name'] = $reg->gname . ' ' . $reg->sname;
             }
             if (count($data)) {
                 $this->email_imported_regs($email, $data);
             }
         }
     } else {
         $passes = ORM::Factory('pass')->with('convention')->find_all();
         $this->template->content = new View('admin/Upload', array('passes' => $passes, 'pass_id' => $pass_id));
     }
 }
开发者ID:halkeye,项目名称:ecmproject,代码行数:85,代码来源:admin.php

示例8: validation

 /**
  * Fetch a validation object from a field or form
  *
  * @access public
  * @param array $array (default: NULL)
  * @return Validation obj
  */
 public function validation(array $array = NULL)
 {
     $this->driver('pre_validate');
     if ($array !== NULL) {
         $validation = new Validation($array);
         $validation->rules($this->alias(), $this->_rules);
         foreach ($this->_fields as $field) {
             $field->driver('pre_validate');
             $validation->rules($field->alias(), $field->get('rules'));
         }
     } else {
         $values = $this->driver('get_validation_values');
         $validation = new Validation($values);
         $this->_add_rules_to_validation($validation);
     }
     $parent = $this->parent(TRUE);
     $validation->bind(':formo', $this);
     $validation->bind(':form_val', $parent->val());
     $validation->bind(':form', $parent);
     return $validation;
 }
开发者ID:bmidget,项目名称:kohana-formo,代码行数:28,代码来源:Formo.php

示例9: valid

 /**
  * Runs business logic validations on this model.
  *
  * You can pass an existing validation object into this method.
  * This will let you add some application specific validations to
  * run on the model. Password validation is a good use case for
  * this.
  *
  * You can use the :model binding in your validation rules to
  * access this model object.
  *
  * @param Validation $validation a previously filled validation obj
  *
  * @return array
  */
 public function valid(Validation $validation = NULL, Validation $default_validation = NULL)
 {
     $data = $validation instanceof Validation ? $validation->copy($validation->data() + $this->as_array()) : $default_validation;
     if (!$default_validation) {
         $data = new Validation($this->as_array());
     }
     $data->bind(':model', $this);
     foreach ($this->_rules as $field => $rules) {
         $data->rules($field, $rules);
     }
     if ($data->check(TRUE)) {
         return TRUE;
     } else {
         throw new Validation_Exception($data);
     }
 }
开发者ID:rjd22,项目名称:gateway_example,代码行数:31,代码来源:model.php


注:本文中的Validation::rules方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。