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


PHP Validation::error方法代碼示例

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


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

示例1: validate_date

 /**
  * date validator
  * 
  * @param Validation $validation
  * @param string $field
  * @param string $value
  * @throws Validation_Exception
  * @return void
  */
 public function validate_date(Validation $validation, $field, $value)
 {
     $stamp = strtotime($value);
     if ($stamp < time() - 31556926) {
         $validation->error($field, 'invalid_date', array($validation[$field]));
     }
     if ($field == "start") {
         // if it is a new reservation, check if time is in the future
         if ($this->id == null && $stamp < time()) {
             $validation->error($field, 'past', array($validation[$field], $value));
         }
         // check if the resaurant is opened on that day
         if (in_array(date("N", $stamp), Kohana::$config->load('smacky.closed'))) {
             $validation->error($field, 'closed', array($validation[$field]));
         }
     }
     if ($field == "end") {
         // check if the end-stamp is after the start-stamp
         if ($value <= $this->start) {
             $validation->error($field, 'invalid_timespan', array($validation[$field], $value));
         }
         // check if max reservation time is not exceeded
         if ($stamp - strtotime($this->start) > Kohana::$config->load('smacky.max-reservation') * 3600) {
             $validation->error($field, 'max_time', array($validation[$field], $value));
         }
     }
 }
開發者ID:runtah17,項目名稱:smacky-tables,代碼行數:36,代碼來源:reservation.php

示例2: unique_identity

 /**
  * Triggers error if identity exists.
  * Validation callback.
  *
  * @param	Validation	Validation object
  * @param	string	  field name
  * @return	void
  */
 public function unique_identity(Validation $validation, $field)
 {
     $identity_exists = (bool) DB::select(array('COUNT("*")', 'total_count'))->from($this->_table_name)->where('identity', '=', $validation['identity'])->and_where('provider', '=', $validation['provider'])->execute($this->_db)->get('total_count');
     if ($identity_exists) {
         $validation->error($field, 'identity_available', array($validation[$field]));
     }
 }
開發者ID:rukku,項目名稱:SwiftRiver,代碼行數:15,代碼來源:identity.php

示例3: checkAdminRoleLimit

 public function checkAdminRoleLimit(Validation $validation, $role)
 {
     $config = \Kohana::$config->load('features.limits');
     if ($config['admin_users'] > 1 && $role == 'admin') {
         $total = $this->repo->getTotalCount(['role' => 'admin']);
         if ($total >= $config['admin_users']) {
             $validation->error('role', 'adminUserLimitReached');
         }
     }
 }
開發者ID:puffadder,項目名稱:platform,代碼行數:10,代碼來源:Update.php

示例4: checkPostTypeLimit

 public function checkPostTypeLimit(Validation $validation)
 {
     $config = \Kohana::$config->load('features.limits');
     if ($config['forms'] !== TRUE) {
         $total_forms = $this->repo->getTotalCount();
         if ($total_forms >= $config['forms']) {
             $validation->error('name', 'postTypeLimitReached');
         }
     }
 }
開發者ID:gjorgiev,項目名稱:platform,代碼行數:10,代碼來源:Update.php

示例5: checkPermissions

 public function checkPermissions(Validation $validation, $permissions)
 {
     if (!$permissions) {
         return;
     }
     foreach ($permissions as $permission) {
         if (!$this->permission_repo->exists($permission)) {
             $validation->error('permissions', 'permissionDoesNotExist', [$permission]);
             return;
         }
     }
 }
開發者ID:tobiasziegler,項目名稱:platform,代碼行數:12,代碼來源:Update.php

示例6: install

 /**
  * 
  * @param array $post
  * @return boolean
  * @throws Installer_Exception
  */
 public function install(array $post)
 {
     if (empty($post)) {
         throw new Installer_Exception('No install data!');
     }
     if (isset($post['password_generate'])) {
         $post['password_field'] = Text::random();
     }
     if (isset($post['admin_dir_name'])) {
         $post['admin_dir_name'] = URL::title($post['admin_dir_name']);
     }
     if (isset($post['db_port'])) {
         $post['db_port'] = (int) $post['db_port'];
     }
     date_default_timezone_set($post['timezone']);
     $this->_session->set('install_data', $post);
     $this->_validation = $this->_valid($post);
     try {
         $this->_db_instance = $this->connect_to_db($post);
     } catch (Database_Exception $exc) {
         $validation = FALSE;
         switch ($exc->getCode()) {
             case 1049:
                 $this->_validation->error('db_name', 'incorrect');
                 $validation = TRUE;
                 break;
             case 2:
                 $this->_validation->error('db_server', 'incorrect')->error('db_user', 'incorrect')->error('db_password', 'incorrect');
                 $validation = TRUE;
                 break;
         }
         if ($validation === TRUE) {
             throw new Validation_Exception($this->_validation, $exc->getMessage(), NULL, $exc->getCode());
         } else {
             throw new Database_Exception($exc->getMessage(), NULL, $exc->getCode());
         }
     }
     Database::$default = 'install';
     Observer::notify('before_install', $post, $this->_validation);
     if (isset($post['empty_database'])) {
         $this->_reset();
     }
     define('TABLE_PREFIX_TMP', Arr::get($post, 'db_table_prefix', ''));
     $this->_import_shema($post);
     $this->_import_dump($post);
     $this->_install_modules($post);
     Observer::notify('install', $post);
     $this->_create_site_config($post);
     $this->_create_config_file($post);
     return TRUE;
 }
開發者ID:ZerGabriel,項目名稱:cms-1,代碼行數:57,代碼來源:installer.php

示例7: valid_range

 public function valid_range(Validation $validation, $field)
 {
     $start = $validation['startDate'];
     $end = $validation['endDate'];
     if (!$start || !$end || $start >= $end) {
         $validation->error($field, 'valid_range', array($validation[$field]));
     }
 }
開發者ID:halkeye,項目名稱:ecmproject,代碼行數:8,代碼來源:pass.php

示例8: is_valid

 /**
  * Validation callback
  *
  * @param   string      $name        Validation name
  * @param   Validation  $validation  Validation object
  * @param   string      $field       Field name
  *
  * @uses    Valid::numeric
  * @uses    Config::get
  */
 public function is_valid($name, Validation $validation, $field)
 {
     // Make sure we have a valid term id set
     if ($name == 'category') {
         if (isset($this->categories) and is_array($this->categories)) {
             foreach ($this->categories as $id => $term) {
                 if ($term == 'last' or !Valid::numeric($term)) {
                     $validation->error('categories', 'invalid', array($validation[$field]));
                 }
             }
         }
     } elseif ($name == 'created') {
         if (!empty($this->author_date) and !($date = strtotime($this->author_date))) {
             $validation->error($field, 'invalid', array($this->author_date));
         } else {
             if (isset($date)) {
                 $this->created = $date;
             }
         }
     } elseif ($name == 'author') {
         if (!empty($this->author_name) and !($account = User::lookup_by_name($this->author_name))) {
             $validation->error($field, 'invalid', array($this->author_name));
         } else {
             if (isset($account)) {
                 $this->author = $account->id;
             }
         }
     } elseif ($name == 'pubdate') {
         if (!empty($this->author_pubdate) and !($date = strtotime($this->author_pubdate))) {
             $validation->error($field, 'invalid', array($validation[$field]));
         } else {
             if (isset($date)) {
                 $this->pubdate = $date;
             }
         }
     } elseif ($name == 'image') {
         if (isset($_FILES['image']['name']) and !empty($_FILES['image']['name'])) {
             $allowed_types = Config::get('media.supported_image_formats', array('jpg', 'png', 'gif'));
             $data = Validation::factory($_FILES)->rule('image', 'Upload::not_empty')->rule('image', 'Upload::valid')->rule('image', 'Upload::type', array(':value', $allowed_types));
             if (!$data->check()) {
                 $validation->error($field, 'invalid', array($validation[$field]));
             }
         }
     }
 }
開發者ID:MenZil-Team,項目名稱:cms,代碼行數:55,代碼來源:post.php

示例9: user_has_avatar

 /**
  * @param Validation $validation
  * @param string $field
  * @param string $value
  */
 public function user_has_avatar($validation, $field, $value)
 {
     if (!$this->user->has('avatars', $value)) {
         $validation->error($field, 'You do not own that avatar');
     }
 }
開發者ID:modulargaming,項目名稱:user,代碼行數:11,代碼來源:Gallery.php

示例10: checkRequiredAttributes

 /**
  * Check required attributes are completed before completing stages
  *
  * @param  Validation $validation
  * @param  Array      $attributes
  * @param  Array      $data
  */
 public function checkRequiredAttributes(Validation $validation, $attributes, $data)
 {
     if (empty($data['completed_stages'])) {
         return;
     }
     // If a stage is being marked completed
     // Check if the required attribute have been completed
     foreach ($data['completed_stages'] as $stage_id) {
         // Load the required attributes
         $required_attributes = $this->attribute_repo->getRequired($stage_id);
         // Check each attribute has been completed
         foreach ($required_attributes as $attr) {
             if (!array_key_exists($attr->key, $attributes)) {
                 $stage = $this->stage_repo->get($stage_id);
                 // If a required attribute isn't completed, throw an error
                 $validation->error('values', 'attributeRequired', [$attr->key, $stage->label]);
             }
         }
     }
 }
開發者ID:hnykda,項目名稱:ushadi-prod-platform,代碼行數:27,代碼來源:Create.php

示例11: validate_commands

 /**
  * Validate item command input when creating an item
  *
  * @param Validation $validation Validation objec
  * @param JSON       $value      Command to validate
  */
 public static function validate_commands($validation, $value)
 {
     $values = json_decode($value, TRUE);
     foreach ($values as $command) {
         $cmd = Item_Command::factory($command['name']);
         if (!$cmd->validate($command['param'])) {
             $validation->error('commands', $command['name']);
         }
     }
 }
開發者ID:modulargaming,項目名稱:item,代碼行數:16,代碼來源:Item.php

示例12: is_valid

 /**
  * Validation callback
  *
  * @param   Validation  $validation  Validation object
  * @param   string      $field       Field name
  * @uses    Valid::numeric
  * @return  void
  */
 public function is_valid(Validation $validation, $field)
 {
     if (empty($this->name) and empty($this->title)) {
         $validation->error('title', 'not_empty', array($this->title));
     } else {
         $text = empty($this->name) ? $this->title : $this->name;
         $this->name = $this->_unique_slug(URL::title($text));
     }
 }
開發者ID:MenZil-Team,項目名稱:cms,代碼行數:17,代碼來源:menu.php

示例13: check_measures

 /**
  * @static
  * @param string $field
  * @param string $value
  * @param Model $model
  * @param Validation $validation
  */
 public static function check_measures($field, $value, $model, $validation)
 {
     if ($value == 'E-Total' and $model->min == 0) {
         $validation->error($field, "E-Total's MIN cannot be zero.");
     }
 }
開發者ID:ragchuck,項目名稱:ra-Log,代碼行數:13,代碼來源:data.php

示例14: _is_unique

 /**
  * Callback for validating that a field is unique.
  *
  * @param   Validation   $data
  * @param   Jelly_Model  $model
  * @param   string       $field
  * @param   string       $value
  * @return  void
  */
 public function _is_unique(Validation $data, Jelly_Model $model, $field, $value)
 {
     // According to the SQL standard NULL is not checked by the unique constraint
     // We also skip this test if the value is the same as the default value
     if ($value !== NULL and $value !== $this->default) {
         // Build query
         $query = Jelly::query($model)->where($field, '=', $value);
         // Limit to one
         $query->limit(1);
         if ($query->count()) {
             // Add error if duplicate found
             $data->error($field, 'unique');
         }
     }
 }
開發者ID:piotrtheis,項目名稱:jelly,代碼行數:24,代碼來源:field.php

示例15: valid_avatar_type

 /**
  * @param Validation $validation
  * @param string $field
  * @param string $value
  */
 public function valid_avatar_type($validation, $field, $value)
 {
     $avatars = $this->get_avatar_drivers();
     $ids = array();
     foreach ($avatars as $avatar) {
         $ids[] = $avatar->id;
     }
     if (!in_array($value, $ids)) {
         $validation->error($field, 'Unknown avatar type');
     }
 }
開發者ID:modulargaming,項目名稱:user,代碼行數:16,代碼來源:Profile.php


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