errors() public method

Access the errors of the record.
See also: lithium\data\Entity::$_errors
public errors ( array | string $field = null, string $value = null ) : mixed
$field array | string If an array, overwrites `$this->_errors` if it is empty, if not, merges the errors with the current values. If a string, and `$value` is not `null`, sets the corresponding key in `$this->_errors` to `$value`. Setting `$field` to `false` will reset the current state.
$value string Value to set.
return mixed Either the `$this->_errors` array, or single value from it.
コード例 #1
0
ファイル: EntityTest.php プロジェクト: WarToaster/HangOn
 public function testErrors()
 {
     $entity = new Entity();
     $errors = array('foo' => 'Something bad happened.');
     $this->assertEqual(array(), $entity->errors());
     $entity->errors($errors);
     $this->assertEqual($errors, $entity->errors());
     $this->assertEqual('Something bad happened.', $entity->errors('foo'));
 }
コード例 #2
0
ファイル: EntityTest.php プロジェクト: unionofrad/lithium
 public function testAppendingErrorsWithMixedSyntax()
 {
     $entity = new Entity();
     $expected = array('Something bad happened.', 'Something really bad happened.');
     $entity->errors('foo', $expected[0]);
     $entity->errors(array('foo' => $expected[1]));
     $this->assertCount(1, $entity->errors());
     $this->assertEqual($expected, $entity->errors('foo'));
 }