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


PHP Validation::rule方法代码示例

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


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

示例1: validate

 /**
  * Default validation field
  * if validation failed method 
  * throw validation exception
  */
 public function validate($value)
 {
     $this->validation = new Validation(array($this->get_name() => $value));
     //$this->validation->label($this->get_name(), $this->get_name());
     if ($this->item['notnull']) {
         if ($value == null) {
             $this->validation->rule($this->get_name(), 'not_empty');
         }
     }
     if (!$this->validation->check()) {
         throw new Validation_Exception($this->validation);
     }
     return $this->validation;
 }
开发者ID:raku,项目名称:MorCMS,代码行数:19,代码来源:execute.php

示例2: validate

 public function validate($data)
 {
     $val = new Validation($data);
     foreach ($this->validator as $key => $rules) {
         foreach ($rules as $rule => $value) {
             if (is_numeric($rule)) {
                 $val->rule($key, $value);
             } else {
                 $val->rule($key, $rule, $value);
             }
         }
     }
     $val->check();
     return $val->errors();
 }
开发者ID:Alex-AG,项目名称:exeltek-po,代码行数:15,代码来源:Form.php

示例3: action_edit_field

 public function action_edit_field()
 {
     $field_id = $this->request->param('options');
     xml::to_XML(array('field' => array('@id' => $field_id, '$content' => User::get_data_field_name($field_id))), $this->xml_content);
     if (count($_POST) && isset($_POST['field_name'])) {
         $post = new Validation($_POST);
         $post->filter('trim');
         $post->rule('Valid::not_empty', 'field_name');
         if ($post->validate()) {
             $post_values = $post->as_array();
             if ($post_values['field_name'] != User::get_data_field_name($field_id) && !User::field_name_available($post_values['field_name'])) {
                 $post->add_error('field_name', 'User::field_name_available');
             }
         }
         // Retry
         if ($post->validate()) {
             $post_values = $post->as_array();
             User::update_field($field_id, $post_values['field_name']);
             $this->add_message('Field ' . $post_values['field_name'] . ' updated');
             $this->set_formdata(array('field_name' => $post_values['field_name']));
         } else {
             $this->add_error('Fix errors and try again');
             $this->add_form_errors($post->errors());
             $this->set_formdata(array_intersect_key($post->as_array(), $_POST));
         }
     } else {
         $this->set_formdata(array('field_name' => User::get_data_field_name($field_id)));
     }
 }
开发者ID:rockymontana,项目名称:kohana-module-pajas,代码行数:29,代码来源:fields.php

示例4: action_show

 public function action_show()
 {
     $arr = [];
     //Получаем данные из формы
     if (isset($_POST['submit'])) {
         //Проверяем введенные данные на корректность
         $post = new Validation($_POST);
         $post->rule('prime', 'not_empty')->rule('prime', 'numeric');
         if ($post->check()) {
             $max = $_POST['prime'];
             $arr = Controller_PrimeNumber::getPrime($max);
             Controller_DataArchive::saveDB($max, $arr);
         } else {
             $errors = $post->errors('comments');
         }
     }
     //Подготавливаем данные для вида
     $view = View::factory('index');
     if (isset($errors)) {
         $view->err = $errors;
     } else {
         if (!empty($arr)) {
             $view->arr = $arr;
         }
     }
     $this->response->body($view);
 }
开发者ID:safronovdanil,项目名称:SiteActive,代码行数:27,代码来源:PrimeNumber.php

示例5: action_entry

 public function action_entry()
 {
     // Set employees node
     $employees_node = $this->xml_content->appendChild($this->dom->createElement('employees'));
     $employees = array('0option' => array('@value' => '0', 'None'));
     $counter = 1;
     foreach (Employees::get() as $employee) {
         $employees[$counter . 'option'] = array('@value' => $employee['id'], $employee['lastname'] . ', ' . $employee['firstname']);
         $counter++;
     }
     xml::to_XML($employees, $employees_node);
     // This is for the select box
     if (count($_POST)) {
         $post = new Validation($_POST);
         $post->filter('trim');
         $post->filter('floatval', 'sum');
         $post->filter('floatval', 'vat');
         $post->rule('strtotime', 'accounting_date');
         $post->rule('strtotime', 'transfer_date');
         $post->rule('Valid::not_empty', 'description');
         if ($post->Validate()) {
             $new_transaction_data = array('accounting_date' => $post->get('accounting_date'), 'transfer_date' => $post->get('transfer_date'), 'description' => $post->get('description'), 'journal_id' => $post->get('journal_id'), 'vat' => $post->get('vat'), 'sum' => $post->get('sum'), 'employee_id' => $post->get('employee_id'));
             if (!isset($_GET['id'])) {
                 $transaction = new Transaction(NULL, $new_transaction_data);
                 $this->add_message('Transaction ' . $transaction->get_id() . ' added');
             } else {
                 $transaction = new Transaction($_GET['id']);
                 $transaction->set($new_transaction_data);
                 $this->add_message('Transaction ' . $transaction->get_id() . ' updated');
                 $this->set_formdata($transaction->get());
             }
         } else {
             $this->add_form_errors($post->errors());
             $this->set_formdata($post->as_array());
         }
     } elseif (isset($_GET['id'])) {
         $transaction = new Transaction($_GET['id']);
         $this->set_formdata($transaction->get());
     } else {
         $this->set_formdata(array('accounting_date' => date('Y-m-d', time()), 'transfer_date' => date('Y-m-d', time())));
     }
 }
开发者ID:rockymontana,项目名称:larvconomy,代码行数:42,代码来源:accounting.php

示例6: action_upload

 public function action_upload()
 {
     $md5 = md5($_FILES['image']['tmp_name']);
     $file = $md5 . '_' . time() . '.' . pathinfo($_FILES['image']['name'])['extension'];
     $fileValidation = new Validation($_FILES);
     $fileValidation->rule('image', 'upload::valid');
     $fileValidation->rule('image', 'upload::type', array(':value', array('jpg', 'png')));
     if ($fileValidation->check()) {
         if ($path = Upload::save($_FILES['image'], $file, DIR_IMAGE)) {
             ORM::factory('File')->set('sid', $this->siteId)->set('name', $_FILES['image']['name'])->set('path', $file)->set('md5', $md5)->set('types', Model_File::FILE_TYPES_IMG)->set('created', time())->set('updated', time())->save();
             $site = ORM::factory('Site')->where('id', '=', $this->siteId)->where('uid', '=', $this->user['id'])->find();
             $site->set('logo', $file)->set('updated', time())->save();
             jsonReturn(1001, '上传成功!', '/media/image/data/' . $file);
         } else {
             jsonReturn(4444, '图片保存失败');
         }
     } else {
         jsonReturn(4444, '图片上传失败');
     }
 }
开发者ID:wangyandong,项目名称:SimpleSite,代码行数:20,代码来源:Site.php

示例7: onValidateDocument

 public function onValidateDocument(Validation $validation, DataSource_Hybrid_Document $doc)
 {
     if ($this->min !== NULL or $this->max !== NULL) {
         $min = $this->min !== NULL ? $this->min : -99999999999;
         $max = $this->max !== NULL ? $this->max : 99999999999;
         $validation->rule($this->name, 'range', array(':value', $min, $max));
     }
     if (!empty($this->_props['regexp'])) {
         if (strpos($this->regexp, '::') !== FALSE) {
             list($class, $method) = explode('::', $this->regexp);
         } else {
             $class = 'Valid';
             $method = $this->regexp;
         }
         if (method_exists($class, $method)) {
             $validation->rule($this->name, array($class, $method));
         } else {
             $validation->rule($this->name, 'regex', array(':value', $this->regexp));
         }
     }
     return parent::onValidateDocument($validation, $doc);
 }
开发者ID:ZerGabriel,项目名称:cms-1,代码行数:22,代码来源:primitive.php

示例8: action_uploadavatar

 public function action_uploadavatar()
 {
     $filename = time() . '_' . $_FILES['image']['name'];
     $file_validation = new Validation($_FILES);
     $file_validation->rule('image', 'upload::valid');
     $file_validation->rule('image', 'upload::type', array(':value', array('jpg', 'png', 'gif', 'jpeg')));
     if ($file_validation->check()) {
         if ($path = Upload::save($_FILES['image'], $filename, DIR_IMAGE)) {
             $image = CacheImage::instance();
             $src = $image->resize($filename, 100, 100);
             $user = Auth::instance()->get_user();
             $user->avatar = $filename;
             $user->save();
             $json = array('success' => 1, 'image' => $src);
         } else {
             $json = array('success' => 0, 'errors' => array('image' => 'The file is not a valid Image'));
         }
     } else {
         $json = array('success' => 0, 'errors' => (array) $file_validation->errors('profile'));
     }
     echo json_encode($json);
     exit;
 }
开发者ID:hemsinfotech,项目名称:kodelearn,代码行数:23,代码来源:account.php

示例9: action_index

 public function action_index()
 {
     $installation_status = Kohana::$config->load('install.status');
     switch ($installation_status) {
         case NOT_INSTALLED:
             if (!$this->check_installation_parameters()) {
                 //$data['title']=__('Installation: something wrong');
                 // $this->data=Arr::merge($this->data, Helper::get_db_settings());
                 $this->data = Arr::merge($this->data, get_object_vars($this->install_config));
                 $res = View::factory('install_form', $this->data)->render();
                 //Model::factory('model_name')->model_method( $data );
             } else {
                 $_post = Arr::map('trim', $_POST);
                 $post = new Validation($_post);
                 $post->rule('db_path', 'not_empty')->rule('db_name', 'not_empty')->rule('db_login', 'not_empty')->rule('installer_login', 'not_empty')->rule('installer_password', 'not_empty');
                 if ($post->check()) {
                     Helper::save_install_settings($post);
                     if (!Model::factory('install')->install($err_list)) {
                         Helper::set_installation_status(NOT_INSTALLED);
                         foreach ($err_list as $e) {
                             $this->data['errors'][] = $e['error'];
                         }
                         $res = View::factory('installing', $this->data)->render();
                     } else {
                         $res = View::factory('installing_ok', $this->data)->render();
                     }
                 } else {
                     // Кажется что-то случилось
                     //$data['title']=__('Installation: something wrong');
                     $this->data['errors'] = $post->errors('validation');
                     $res = View::factory('install_form', $this->data)->render();
                 }
             }
             break;
         case INSTALLING:
             $res = View::factory('installing')->render();
             break;
         case INSTALLED:
             //                    $res = View::factory('/')->render();
             $this->redirect('/');
             break;
         default:
             //                    $res = View::factory('/')->render();
             $this->redirect('/');
             break;
     }
     // Save result / Сохраняем результат
     $this->_result = $res;
 }
开发者ID:g-a-g,项目名称:its2015,代码行数:49,代码来源:install.php

示例10: action_role

 /**
  * Edit Tags
  * if id is set, instanciate an edit function
  * if not instanciate an add tag function.
  */
 public function action_role()
 {
     $this->xml_content_types = $this->xml_content->appendChild($this->dom->createElement('roles'));
     xml::to_XML(Uvtag::get_tags(), $this->xml_content_types, 'role');
     if (!empty($_POST)) {
         $post = new Validation($_POST);
         $post->filter('trim');
         $post->rule('Valid::not_empty', 'role');
         $post->rule('Valid::not_empty', 'uri');
         if (isset($role)) {
             $tag->update($post->as_array());
             $this->add_message('Role name updated');
         } else {
             if (Uvtag::add($post->get('role'), $post->get('uri'))) {
                 $this->add_message('Role "' . $post->get('name') . '" was added');
             } else {
                 $this->add_message('Role "' . $post->get('name') . '" could not be added');
             }
         }
     } elseif (isset($tag)) {
         // Set the form input to the tag name.
         $this->set_formdata($tag->get());
     }
 }
开发者ID:rockymontana,项目名称:kohana-module-pajas,代码行数:29,代码来源:roles.php

示例11: onValidateDocument

 public function onValidateDocument(Validation $validation, DataSource_Hybrid_Document $doc)
 {
     $validation->rule($this->name, 'color');
     return parent::onValidateDocument($validation, $doc);
 }
开发者ID:ZerGabriel,项目名称:cms-1,代码行数:5,代码来源:color.php

示例12: action_payout

 public function action_payout()
 {
     // Set employees node
     $employees_node = $this->xml_content->appendChild($this->dom->createElement('employees'));
     $employees = array();
     $counter = 0;
     $employees_from_model = Employees::get();
     foreach ($employees_from_model as $employee) {
         $employees[$counter . 'option'] = array('@value' => $employee['id'], $employee['lastname'] . ', ' . $employee['firstname']);
         $counter++;
     }
     xml::to_XML($employees, $employees_node);
     // This is for the select box
     xml::to_XML($employees_from_model, $employees_node, 'employee', 'id');
     if (isset($_GET['id'])) {
         if (count($_POST)) {
             $post = new Validation($_POST);
             $post->filter('trim');
             $salary->set($post->as_array());
         }
         $this->set_formdata($salary->get());
         xml::to_XML(array('statuses' => array('1option' => array('@value' => 'active', 'Active'), '2option' => array('@value' => 'inactive', 'Inactive'))), $this->xml_content);
         xml::to_XML($employee->get(), $this->xml_content->appendChild($this->dom->createElement('employee')), NULL, 'id');
         $this->add_message('Employee ' . $_GET['id'] . ' information updated');
     } elseif (count($_POST)) {
         // Add new payout
         $post = new Validation($_POST);
         $post->filter('trim');
         $post->rule('Valid::digit', 'amount');
         $post->rule('strtotime', 'date');
         if ($post->validate()) {
             $post_array = $post->as_array();
             $transaction_data = array('accounting_date' => date('Y-m-d', strtotime($post_array['date'])), 'transfer_date' => date('Y-m-d', strtotime($post_array['date'])), 'description' => 'Salary payout', 'journal_id' => NULL, 'vat' => 0, 'sum' => -$post_array['amount'], 'employee_id' => $post_array['employee_id']);
             $transaction = new Transaction(NULL, $transaction_data);
             if ($id = $transaction->get_id()) {
                 $this->add_message('New transaction added (ID ' . $id . ')');
             } else {
                 $this->add_error('Something fucked up');
             }
         } else {
             $this->set_formdata($post->as_array());
             $errors = $post->errors();
             $this->add_form_errors($errors);
             if (isset($errors['date'])) {
                 $this->add_form_errors(array('date' => 'Invalid date format'));
             }
             if (isset($errors['amount'])) {
                 $this->add_form_errors(array('amount' => 'Must be numbers ONLY'));
             }
         }
     }
 }
开发者ID:rockymontana,项目名称:larvconomy,代码行数:52,代码来源:wages.php

示例13: validate

 /**
  * Validate the data, returning array of errors (if any).
  *
  * @return array
  */
 public function validate()
 {
     $validation = new Validation($this->_data);
     foreach ($this->_fields as $fieldName => $fieldOptions) {
         foreach (Arr::get($fieldOptions, 'rules', array()) as $fieldRule) {
             if (is_array($fieldRule)) {
                 // Take the 1st param as the name, the rest as params.
                 $ruleName = array_shift($fieldRule);
                 $ruleParams = $fieldRule;
             } else {
                 // Just use the rule as passed with no params.
                 $ruleName = $fieldRule;
                 $ruleParams = NULL;
             }
             // Check if the named function is actually a method on this object.
             if (!function_exists($ruleName) && method_exists($this, $ruleName)) {
                 $ruleName = array($this, $ruleName);
             }
             $validation->rule($fieldName, $ruleName, $ruleParams);
             $validation->label($fieldName, Arr::get($fieldOptions, 'label', $fieldName));
         }
     }
     if ($validation->check()) {
         $this->_errors = array();
         return TRUE;
     } else {
         if (!(bool) ($errorMessageFile = $this->_errorMessageFile)) {
             // Konform_Contact => 'konform/contact'
             $errorMessageFile = strtolower(str_replace('_', '/', get_class($this)));
         }
         $this->_errors = $validation->errors($errorMessageFile);
         return FALSE;
     }
 }
开发者ID:drarok,项目名称:konform,代码行数:39,代码来源:Konform.php

示例14: 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

示例15: action_user

 public function action_user()
 {
     $formdata = array();
     if (isset($_GET['id'])) {
         $user = new User($_GET['id'], FALSE, FALSE, 'default', FALSE);
         if (!$user->logged_in()) {
             $this->redirect();
         }
     }
     $this->list_available_data_fields();
     if (!empty($_POST) && isset($_POST['username']) && isset($_POST['password'])) {
         $post = new Validation($_POST);
         $post->filter('trim');
         $post->filter('strtolower', 'username');
         $post->rule('Valid::not_empty', 'username');
         if (isset($user)) {
             if ($_POST['username'] != $user->get_username()) {
                 $post->rule('User::username_available', 'username');
             }
         } else {
             $post->rule('User::username_available', 'username');
         }
         if (!isset($user)) {
             $post->rule('Valid::not_empty', 'password');
         }
         if (isset($_POST['do_add_field'])) {
             // Add another user data field and save no data, but repopulate the form fields
             if (!isset($_SESSION['detail_fields'])) {
                 $_SESSION['detail_fields'] = array();
             }
             $_SESSION['detail_fields'][] = $_POST['add_field'];
             // Reconstruct the form data to repopulate the form
             $formdata = array();
             $counter = 0;
             $post_values = $post->as_array();
             foreach ($post_values as $field => $data) {
                 if (substr($field, 0, 8) == 'fieldid_') {
                     foreach ($data as $data_piece) {
                         $counter++;
                         $formdata['field_' . substr($field, 8) . '_' . $counter] = trim($data_piece);
                     }
                 } elseif ($field == 'username') {
                     $formdata[$field] = $post_values[$field];
                 }
             }
         } else {
             // Check for form errors
             if ($post->validate()) {
                 // No form errors, add the user!
                 $post_values = $post->as_array();
                 // Erase the empty data fields
                 foreach ($post_values as $key => $value) {
                     if (substr($key, 0, 8) == 'fieldid_' && is_array($value)) {
                         foreach ($value as $nr => $value_piece) {
                             if ($value_piece == '') {
                                 unset($post_values[$key][$nr]);
                             }
                         }
                     }
                 }
                 // Organize the field data and set the session fields
                 $fields = $_SESSION['detail_fields'] = array();
                 foreach ($post_values as $key => $value) {
                     if (substr($key, 0, 6) == 'field_') {
                         list($foobar, $field_id, $field_nr) = explode('_', $key);
                         $fields[User::get_data_field_name($field_id)][] = $value;
                     }
                 }
                 if (!isset($_GET['id'])) {
                     // Actually add the user
                     User::new_user($post_values['username'], $post_values['password'], $fields);
                     $this->add_message('User ' . $post_values['username'] . ' added');
                 } elseif (isset($user)) {
                     $user->set_user_data(array_merge($fields, array('username' => $post_values['username'], 'password' => $post_values['password'])), TRUE);
                     $this->add_message('User data saved');
                 }
             } else {
                 // Form errors detected!
                 $this->add_error('Fix errors and try again');
                 $this->add_form_errors($post->errors());
                 $formdata = array();
                 $counter = 0;
                 $post_values = $post->as_array();
                 foreach ($post_values as $field => $data) {
                     if (substr($field, 0, 8) == 'fieldid_') {
                         foreach ($data as $data_piece) {
                             $counter++;
                             $formdata['field_' . substr($field, 8) . '_' . $counter] = trim($data_piece);
                         }
                     } elseif ($field == 'username') {
                         $formdata[$field] = $post_values[$field];
                     }
                 }
             }
         }
     }
     if (isset($user)) {
         $formdata = array('username' => $user->get_username());
         $counter = 0;
         foreach ($user->get_user_data() as $field => $data) {
//.........这里部分代码省略.........
开发者ID:rockymontana,项目名称:kohana-module-pajas,代码行数:101,代码来源:users.php


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