Class Phalcon\Mvc\Model\Message

implements Phalcon\Mvc\Model\MessageInterface

Source on GitHub

Encapsulates validation info generated before save/delete records fails

  1. <?php
  2. use Phalcon\Mvc\Model\Message as Message;
  3. class Robots extends \Phalcon\Mvc\Model
  4. {
  5. public function beforeSave()
  6. {
  7. if ($this->name === "Peter") {
  8. $text = "A robot cannot be named Peter";
  9. $field = "name";
  10. $type = "InvalidValue";
  11. $message = new Message($text, $field, $type);
  12. $this->appendMessage($message);
  13. }
  14. }
  15. }

Methods

public __construct (string $message, [string | array $field], [string $type], [Phalcon\Mvc\ModelInterface $model], [int | null $code])

Phalcon\Mvc\Model\Message constructor

public setType (mixed $type)

Sets message type

public getType ()

Returns message type

public setMessage (mixed $message)

Sets verbose message

public getMessage ()

Returns verbose message

public setField (mixed $field)

Sets field name related to message

public getField ()

Returns field name related to message

public setModel (Phalcon\Mvc\ModelInterface $model)

Set the model who generates the message

public setCode (mixed $code)

Sets code for the message

public getModel ()

Returns the model that produced the message

public getCode ()

Returns the message code

public __toString ()

Magic __toString method returns verbose message

public static __set_state (array $message)

Magic __set_state helps to re-build messages variable exporting