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


PHP Entity::errors方法代码示例

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


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

示例1: beforeSave

 public function beforeSave(Event $event, Entity $entity, ArrayObject $options)
 {
     if ($entity->isNew() && empty($entity->user_id)) {
         $entity->errors('user_id', ['not_found', 'User not found']);
         $entity->errors('net_id', ['not_found', 'User not found']);
         return false;
     }
 }
开发者ID:byu-oit-appdev,项目名称:byusa-clubs,代码行数:8,代码来源:MatchUserBehavior.php

示例2: errors

 /**
  * Skip error checking for the actual save operation since
  * the entity is checked for errors manually within the KeyValueBehavior.
  *
  * @param string|array|null $field The field to get errors for, or the array of errors to set.
  * @param string|array|null $errors The errors to be set for $field
  * @param bool $overwrite Whether or not to overwrite pre-existing errors for $field
  * @return array|\Cake\Datasource\EntityInterface
  */
 public function errors($field = null, $errors = null, $overwrite = false)
 {
     if (isset($this->_properties['scope'])) {
         $this->_errors = [];
     }
     return parent::errors($field, $errors, $overwrite);
 }
开发者ID:wasabi-cms,项目名称:core,代码行数:16,代码来源:Setting.php

示例3: __construct

 /**
  * Constructor
  *
  * @param \Cake\ORM\Entity $entity Entity
  * @param int $code code to report to client
  */
 public function __construct(Entity $entity, $code = 422)
 {
     $this->_validationErrors = array_filter((array) $entity->errors());
     $flat = Hash::flatten($this->_validationErrors);
     $errorCount = $this->_validationErrorCount = count($flat);
     $this->message = __dn('crud', 'A validation error occurred', '{0} validation errors occurred', $errorCount, [$errorCount]);
     parent::__construct($this->message, $code);
 }
开发者ID:AmuseXperience,项目名称:api,代码行数:14,代码来源:ValidationException.php

示例4: beforeSave

 /**
  * Before save callback.
  *
  * @param \Cake\Event\Event $event The beforeSave event that was fired
  * @param \Cake\ORM\Entity $entity The entity that is going to be saved
  * @return bool
  */
 public function beforeSave(Event $event, Entity $entity)
 {
     $addressColumn = $this->_config['addressColumn'];
     $latitudeColumn = $this->_config['latitudeColumn'];
     $longitudeColumn = $this->_config['longitudeColumn'];
     $parameters = (array) $this->_config['parameters'];
     $requireSuccess = $this->_config['requireSuccess'];
     if (is_array($addressColumn)) {
         $address = [];
         foreach ($addressColumn as $column) {
             if (!empty($entity->{$column})) {
                 $address[] = $entity->{$column};
             }
         }
         $address = implode(', ', $address);
     } else {
         $address = $entity->{$addressColumn};
     }
     $parameters['address'] = $address;
     $parameters['sensor'] = 'false';
     $url = 'http://maps.googleapis.com/maps/api/geocode/json';
     $http = new Client();
     $response = $http->get($url, $parameters);
     $response = json_decode($response->body());
     if ($response->status == 'OK') {
         $entity->{$latitudeColumn} = floatval($response->results[0]->geometry->location->lat);
         $entity->{$longitudeColumn} = floatval($response->results[0]->geometry->location->lng);
         return true;
     } else {
         if ($requireSuccess) {
             $entity->errors($addressColumn, 'Could not geocode address');
             return false;
         } else {
             return true;
         }
     }
 }
开发者ID:chris48s,项目名称:cakephp-geocoder,代码行数:44,代码来源:GeocodableBehavior.php

示例5: testValidationErrorMultipleMessages

 public function testValidationErrorMultipleMessages()
 {
     $entity = new Entity();
     $entity->errors(['title' => ['error message'], 'body' => ['another field message']]);
     $Exception = new ValidationException($entity);
     $Controller = $this->getMock('Cake\\Controller\\Controller', ['render']);
     $Controller->request = new Request();
     $Controller->response = new Response();
     $Renderer = $this->getMock('Crud\\Error\\ExceptionRenderer', ['_getController'], [], '', false);
     $Renderer->expects($this->once())->method('_getController')->with()->will($this->returnValue($Controller));
     $Renderer->__construct($Exception);
     $Renderer->render();
     $expected = ['code' => 422, 'url' => $Controller->request->here(), 'message' => '2 validation errors occurred', 'errorCount' => 2, 'errors' => ['title' => ['error message'], 'body' => ['another field message']], 'exception' => ['class' => 'Crud\\Error\\Exception\\ValidationException', 'code' => 422, 'message' => '2 validation errors occurred']];
     $data = $Controller->viewVars['data'];
     unset($data['trace']);
     $this->assertEquals($expected, $data);
 }
开发者ID:AmuseXperience,项目名称:api,代码行数:17,代码来源:ExceptionRendererTest.php

示例6: changePassword

 /**
  * Changes the password for an user.
  *
  * @param \Cake\ORM\Entity $entity User entity
  * @return boolean
  */
 public function changePassword(Entity $entity)
 {
     if ($entity->errors()) {
         return false;
     }
     $entity->password = $this->hashPassword($entity->password);
     if ($this->_table->save($entity)) {
         return true;
     }
     return false;
 }
开发者ID:djonatanb,项目名称:cakephp-user-tools,代码行数:17,代码来源:UserBehavior.php

示例7: testDebugInfo

 /**
  * Tests __debugInfo
  *
  * @return void
  */
 public function testDebugInfo()
 {
     $entity = new Entity(['foo' => 'bar'], ['markClean' => true]);
     $entity->somethingElse = 'value';
     $entity->accessible('name', true);
     $entity->virtualProperties(['baz']);
     $entity->dirty('foo', true);
     $entity->errors('foo', ['An error']);
     $entity->source('foos');
     $result = $entity->__debugInfo();
     $expected = ['foo' => 'bar', 'somethingElse' => 'value', '[new]' => true, '[accessible]' => ['*' => true, 'name' => true], '[dirty]' => ['somethingElse' => true, 'foo' => true], '[original]' => [], '[virtual]' => ['baz'], '[errors]' => ['foo' => ['An error']], '[repository]' => 'foos'];
     $this->assertSame($expected, $result);
 }
开发者ID:jeremyheaton,项目名称:ultiswap,代码行数:18,代码来源:EntityTest.php

示例8: testMultiRecordForm

 /**
  * Test the generation of fields for a multi record form.
  *
  * @return void
  */
 public function testMultiRecordForm()
 {
     $this->loadFixtures('Articles', 'Comments');
     $articles = TableRegistry::get('Articles');
     $articles->hasMany('Comments');
     $comment = new Entity(['comment' => 'Value']);
     $article = new Article(['comments' => [$comment]]);
     $this->Form->create([$article]);
     $result = $this->Form->input('0.comments.1.comment');
     //@codingStandardsIgnoreStart
     $expected = ['div' => ['class' => 'input textarea'], 'label' => ['for' => '0-comments-1-comment'], 'Comment', '/label', 'textarea' => ['name', 'id' => '0-comments-1-comment', 'rows' => 5], '/textarea', '/div'];
     //@codingStandardsIgnoreEnd
     $this->assertHtml($expected, $result);
     $result = $this->Form->input('0.comments.0.comment');
     //@codingStandardsIgnoreStart
     $expected = ['div' => ['class' => 'input textarea'], 'label' => ['for' => '0-comments-0-comment'], 'Comment', '/label', 'textarea' => ['name', 'id' => '0-comments-0-comment', 'rows' => 5], 'Value', '/textarea', '/div'];
     //@codingStandardsIgnoreEnd
     $this->assertHtml($expected, $result);
     $comment->errors('comment', ['Not valid']);
     $result = $this->Form->input('0.comments.0.comment');
     //@codingStandardsIgnoreStart
     $expected = ['div' => ['class' => 'input textarea error'], 'label' => ['for' => '0-comments-0-comment'], 'Comment', '/label', 'textarea' => ['name', 'class' => 'form-error', 'id' => '0-comments-0-comment', 'rows' => 5], 'Value', '/textarea', ['div' => ['class' => 'error-message']], 'Not valid', '/div', '/div'];
     //@codingStandardsIgnoreEnd
     $this->assertHtml($expected, $result);
     TableRegistry::get('Comments')->validator('default')->allowEmpty('comment', false);
     $result = $this->Form->input('0.comments.1.comment');
     //@codingStandardsIgnoreStart
     $expected = ['div' => ['class' => 'input textarea required'], 'label' => ['for' => '0-comments-1-comment'], 'Comment', '/label', 'textarea' => ['name', 'required' => 'required', 'id' => '0-comments-1-comment', 'rows' => 5], '/textarea', '/div'];
     //@codingStandardsIgnoreEnd
     $this->assertHtml($expected, $result);
 }
开发者ID:jeremyheaton,项目名称:ultiswap,代码行数:36,代码来源:FormHelperTest.php

示例9: invalidate

 /**
  * @param \Cake\ORM\Entity $entity
  * @return void
  */
 protected function invalidate($entity)
 {
     $errorMessage = $this->_config['validationError'] !== null ? $this->_config['validationError'] : __('Could not geocode this address. Please refine.');
     if ($errorMessage === false) {
         return;
     }
     $fields = (array) $this->_config['address'];
     foreach ($fields as $field) {
         if (!is_array($errorMessage)) {
             $entity->errors($field, $errorMessage);
         }
         $message = !empty($errorMessage[$field]) ? $errorMessage[$field] : null;
         if (!$message) {
             continue;
         }
         $entity->errors($field, $message);
     }
 }
开发者ID:dereuromark,项目名称:cakephp-geo,代码行数:22,代码来源:GeocoderBehavior.php

示例10: testDebugInfo

 /**
  * Tests __debugInfo
  *
  * @return void
  */
 public function testDebugInfo()
 {
     $entity = new Entity(['foo' => 'bar'], ['markClean' => true]);
     $entity->accessible('name', true);
     $entity->virtualProperties(['baz']);
     $entity->dirty('foo', true);
     $entity->errors('foo', ['An error']);
     $entity->source('foos');
     $result = $entity->__debugInfo();
     $expected = ['new' => true, 'accessible' => ['*' => true, 'name' => true], 'properties' => ['foo' => 'bar'], 'dirty' => ['foo' => true], 'original' => [], 'virtual' => ['baz'], 'errors' => ['foo' => ['An error']], 'repository' => 'foos'];
     $this->assertSame($expected, $result);
 }
开发者ID:RogerSchmeier,项目名称:Webtruck,代码行数:17,代码来源:EntityTest.php

示例11: resetPassword

 /**
  * Password reset, compares the two passwords and saves the new password.
  *
  * @param \Cake\ORM\Entity $user Entity object.
  * @return void
  */
 public function resetPassword(Entity $user)
 {
     if (!$user->errors()) {
         $user->{$this->_field('password')} = $this->hashPassword($user->{$this->_field('password')});
         $user->{$this->_field('passwordToken')} = null;
         $user->{$this->_field('passwordTokenExpires')} = null;
         return $this->_table->save($user, ['checkRules' => false]);
     }
     return false;
 }
开发者ID:burzum,项目名称:cakephp-user-tools,代码行数:16,代码来源:UserBehavior.php

示例12: testMultiRecordForm

 /**
  * Test the generation of fields for a multi record form.
  *
  * @return void
  */
 public function testMultiRecordForm()
 {
     $this->loadFixtures('Article', 'Comment');
     $articles = TableRegistry::get('Articles');
     $articles->hasMany('Comments');
     $comment = new Entity(['comment' => 'Value']);
     $article = new Article(['comments' => [$comment]]);
     $this->Form->create([$article]);
     $result = $this->Form->input('0.comments.1.comment');
     $expected = array('div' => array('class' => 'input textarea'), 'label' => array('for' => '0-comments-1-comment'), 'Comment', '/label', 'textarea' => array('name', 'type', 'id' => '0-comments-1-comment'), '/textarea', '/div');
     $this->assertTags($result, $expected);
     $result = $this->Form->input('0.comments.0.comment');
     $expected = array('div' => array('class' => 'input textarea'), 'label' => array('for' => '0-comments-0-comment'), 'Comment', '/label', 'textarea' => array('name', 'type', 'id' => '0-comments-0-comment'), 'Value', '/textarea', '/div');
     $this->assertTags($result, $expected);
     $comment->errors('comment', ['Not valid']);
     $result = $this->Form->input('0.comments.0.comment');
     $expected = array('div' => array('class' => 'input textarea error'), 'label' => array('for' => '0-comments-0-comment'), 'Comment', '/label', 'textarea' => array('name', 'type', 'class' => 'form-error', 'id' => '0-comments-0-comment'), 'Value', '/textarea', array('div' => array('class' => 'error-message')), 'Not valid', '/div', '/div');
     $this->assertTags($result, $expected);
     TableRegistry::get('Comments')->validator('default')->allowEmpty('comment', false);
     $result = $this->Form->input('0.comments.1.comment');
     $expected = array('div' => array('class' => 'input textarea required'), 'label' => array('for' => '0-comments-1-comment'), 'Comment', '/label', 'textarea' => array('name', 'type', 'required' => 'required', 'id' => '0-comments-1-comment'), '/textarea', '/div');
     $this->assertTags($result, $expected);
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:28,代码来源:FormHelperTest.php

示例13: validateResource

 /**
  * Validates a resource and returns the validation errors.
  *
  * @param Cake\ORM\Entity $resource
  *
  * @return array
  */
 public function validateResource(Entity &$resource)
 {
     $errors = $this->getResourceValidator()->errors($resource->toArray());
     $resource->errors($errors, null, true);
     return $errors;
 }
开发者ID:bus-factor,项目名称:cakephp-json-rest-api,代码行数:13,代码来源:ResourcesTrait.php

示例14: beforeSave

 /**
  * Callback for Model.beforeSave event.
  *
  * @param \Cake\Event\Event $event The afterSave event that was fired.
  * @param \Cake\ORM\Entity $entity The entity that was saved.
  * @param \ArrayObject $options Options.
  * @return void
  */
 public function beforeSave(Event $event, Entity $entity, ArrayObject $options)
 {
     $slugField = $this->config('field');
     $fields = (array) $this->config('displayField');
     $separator = $this->config('separator');
     if (!$entity->isNew() || $entity->dirty($slugField)) {
         return;
     }
     $parts = [];
     foreach ($fields as $field) {
         if ($entity->errors($field)) {
             return;
         }
         $parts[] = $entity->{$field};
     }
     $entity->set($slugField, $this->slug($entity, implode($separator, $parts), $separator));
 }
开发者ID:jorgeandrescastro,项目名称:Slug,代码行数:25,代码来源:SlugBehavior.php

示例15: changePassword

 /**
  * Changes the password for an user.
  *
  * @param \Cake\ORM\Entity $entity User entity
  * @return boolean
  */
 public function changePassword(Entity $entity)
 {
     $validator = $this->_table->validator('default');
     $validator->provider('userTable', $this->_table);
     $validator->add('old_password', 'notBlank', ['rule' => 'notBlank', 'message' => __d('userTools', 'Enter your old password.')]);
     $validator->add('old_password', 'oldPassword', ['rule' => ['validateOldPassword', 'password'], 'provider' => 'userTable', 'message' => __d('user_tools', 'Wrong password, please try again.')]);
     $this->_table->validator('default', $validator);
     if ($entity->errors()) {
         return false;
     }
     $entity->password = $this->hashPassword($entity->password);
     if ($this->_table->save($entity, ['validate' => false])) {
         return true;
     }
     return false;
 }
开发者ID:nielin,项目名称:cakephp-user-tools,代码行数:22,代码来源:UserBehavior.php


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