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


PHP Table::validator方法代码示例

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


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

示例1: addValidationRules

 public function addValidationRules()
 {
     $add_validation_rules = $this->config('add_validation_rules');
     if ($add_validation_rules) {
         $this->_table->validator()->add('parent_id', 'child_of_itself', ['rule' => function ($value, $context) {
             if (!$context['newRecord'] && $context['data']['parent_id'] == $context['data']['id']) {
                 return false;
             }
             return true;
         }, 'message' => __d('alaxos', 'a node can not be child of itself')]);
         $this->_table->validator()->add('parent_id', 'child_of_child', ['rule' => function ($value, $context) {
             if (!$context['newRecord']) {
                 $child_nodes = $context['providers']['table']->find('children', ['for' => $context['data']['id']]);
                 $children_ids = $child_nodes->extract('id')->toArray();
                 if (in_array($context['data']['parent_id'], $children_ids)) {
                     return false;
                 }
             }
             return true;
         }, 'message' => __d('alaxos', 'a node can not be child of one of its children')]);
     }
 }
开发者ID:alaxos,项目名称:cakephp3-libs,代码行数:22,代码来源:AncestorBehavior.php

示例2: _validate

 /**
  * Returns the validation errors for a data set based on the passed options
  *
  * @param array $data The data to validate.
  * @param array $options The options passed to this marshaller.
  * @param bool $isNew Whether it is a new entity or one to be updated.
  * @return array The list of validation errors.
  * @throws \RuntimeException If no validator can be created.
  */
 protected function _validate($data, $options, $isNew)
 {
     if (!$options['validate']) {
         return [];
     }
     if ($options['validate'] === true) {
         $options['validate'] = $this->_table->validator('default');
     }
     if (is_string($options['validate'])) {
         $options['validate'] = $this->_table->validator($options['validate']);
     }
     if (!is_object($options['validate'])) {
         throw new RuntimeException(sprintf('validate must be a boolean, a string or an object. Got %s.', gettype($options['validate'])));
     }
     return $options['validate']->errors($data, $isNew);
 }
开发者ID:rlugojr,项目名称:cakephp,代码行数:25,代码来源:Marshaller.php

示例3: _processValidation

 /**
  * Validates the $entity if the 'validate' key is not set to false in $options
  * If not empty it will construct a default validation object or get one with
  * the name passed in the key
  *
  * @param \Cake\ORM\Entity $entity The entity to validate
  * @param \ArrayObject $options The option for processing validation
  * @return bool true if the entity is valid, false otherwise
  */
 protected function _processValidation($entity, $options)
 {
     $type = is_string($options['validate']) ? $options['validate'] : 'default';
     $validator = $this->_table->validator($type);
     $pass = compact('entity', 'options', 'validator');
     $event = $this->_table->dispatchEvent('Model.beforeValidate', $pass);
     if ($event->isStopped()) {
         return (bool) $event->result;
     }
     if (!count($validator)) {
         return true;
     }
     $success = !$entity->validate($validator);
     $event = $this->_table->dispatchEvent('Model.afterValidate', $pass);
     if ($event->isStopped()) {
         $success = (bool) $event->result;
     }
     return $success;
 }
开发者ID:neilan35,项目名称:betterwindow1,代码行数:28,代码来源:EntityValidator.php

示例4: testValidatorSetter

 /**
  * Tests that it is possible to set a custom validator under a name
  *
  * @return void
  */
 public function testValidatorSetter()
 {
     $table = new Table();
     $validator = new \Cake\Validation\Validator();
     $table->validator('other', $validator);
     $this->assertSame($validator, $table->validator('other'));
     $this->assertSame($table, $validator->provider('table'));
 }
开发者ID:jdaosavanh,项目名称:clickerwebapp,代码行数:13,代码来源:TableTest.php


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