Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Response.php
Go to the documentation of this file.
1 <?php
9 
12 {
16  const RESPONSE_CHARSET = 'utf-8';
17 
21  const MESSAGE_TYPE_SUCCESS = 'success';
22 
23  const MESSAGE_TYPE_ERROR = 'error';
24 
25  const MESSAGE_TYPE_WARNING = 'warning';
26 
32  const HTTP_OK = 200;
33 
37  protected $_messages = [];
38 
45  public function setMimeType($mimeType)
46  {
47  return $this->setHeader('Content-Type', "{$mimeType}; charset=" . self::RESPONSE_CHARSET, true);
48  }
49 
59  public function addMessage($message, $code, $params = [], $type = self::MESSAGE_TYPE_ERROR)
60  {
61  $params['message'] = $message;
62  $params['code'] = $code;
63  $this->_messages[$type][] = $params;
64  return $this;
65  }
66 
72  public function hasMessages()
73  {
74  return (bool)count($this->_messages) > 0;
75  }
76 
82  public function getMessages()
83  {
84  return $this->_messages;
85  }
86 
92  public function clearMessages()
93  {
94  $this->_messages = [];
95  return $this;
96  }
97 }
setHeader($name, $value, $replace=false)
$message
$type
Definition: item.phtml:13
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18
addMessage($message, $code, $params=[], $type=self::MESSAGE_TYPE_ERROR)
Definition: Response.php:59
$code
Definition: info.phtml:12