本文整理汇总了PHP中Phalcon\Mvc\Model::getMessages方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::getMessages方法的具体用法?PHP Model::getMessages怎么用?PHP Model::getMessages使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\Mvc\Model
的用法示例。
在下文中一共展示了Model::getMessages方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getErrorMessages
/**
* Modelのエラーメッセージを取得
* @return array
*/
public function getErrorMessages()
{
foreach ($this->model->getMessages() as $msgs) {
$errMsgs[] = $msgs->getMessage();
}
return $errMsgs;
}
示例2: showModelErrors
public function showModelErrors(Model $model, Form $form)
{
foreach ($model->getMessages() as $message) {
$fieldName = $message->getField();
$form->addModelError($fieldName, $message->getMessage());
}
}
示例3: getMessages
/**
* Replace/translate default messages generated by the ORM.
*
* @return array
*/
public function getMessages()
{
foreach (parent::getMessages() as $message) {
switch ($message->getType()) {
case 'PresenceOf':
$message->setMessage('The field ' . $message->getField() . ' is required');
break;
case 'Uniqueness':
$message->setMessage('The field ' . $message->getField() . ' must be unique');
break;
case 'Email':
$message->setMessage('The field ' . $message->getField() . ' must contain a valid email');
break;
case 'Url':
$message->setMessage('The field ' . $message->getField() . ' must contain a valid url');
break;
case 'InclusionIn':
$message->setMessage('The field ' . $message->getField() . ' must contain a value in [' . implode(',', $message->getDomain()) . ']');
break;
case 'DateValidator':
$message->setMessage('The field ' . $message->getField() . ' must contain a valid date.');
break;
case 'TimestampValidator':
$message->setMessage('The field ' . $message->getField() . ' must contain a valid timestamps.');
break;
}
}
return parent::getMessages();
}
示例4: createModelErrorMessages
/**
* Recebe um model e une as excessões para retornar em texto
*
* @param \Phalcon\Mvc\Model $model
* @return string
*/
public static function createModelErrorMessages(\Phalcon\Mvc\Model $model)
{
$excepts = [];
foreach ($model->getMessages() as $message) {
$excepts[] = $message;
}
return implode("\n", $excepts);
}
示例5: getMessages
/**
* @param bool $bAsString
* @return \Phalcon\Mvc\Model\MessageInterface[]|string
*/
public function getMessages($bAsString = false)
{
if (!$bAsString) {
return parent::getMessages();
} else {
return implode(', ', parent::getMessages());
}
}
示例6: databaseErrorLog
/**
* 数据库操作异常
* @param \Phalcon\Mvc\Model $model
* @return bool
*/
public function databaseErrorLog($model)
{
$error = '';
foreach ($model->getMessages() as $msg) {
$error .= $msg . ',';
}
$this->di->get('logger')->error('数据库异常, GET:' . json_encode($_GET) . ', POST:' . json_encode($_POST) . ', error: ' . $error);
return false;
}
示例7: logDatabaseError
/**
* 数据库操作异常
* @param \Phalcon\Mvc\Model $model
*/
public function logDatabaseError($model)
{
if ($this->di->offsetExists('logger') == false) {
return;
}
$error = '';
foreach ($model->getMessages() as $msg) {
$error .= $msg . ',';
}
$this->di->get('logger')->error('数据库异常, GET:' . json_encode($_GET) . ', POST: ' . json_encode($_POST) . ', error: ' . $error);
}
示例8: delete
public function delete()
{
$response = array();
if (parent::delete() == false) {
foreach (parent::getMessages() as $message) {
$response['errors'][] = (string) $message;
}
} else {
$response['msg'] = 'ok';
}
return $response;
}
示例9: getMessages
public function getMessages($filter = null)
{
foreach (parent::getMessages() as $message) {
switch ($message->getType()) {
case 'Email':
$message->setMessage('Указан не действительный E-mail.');
break;
case 'PresenceOf':
$message->setMessage('Поле "' . $this->getLabel($message->getField()) . '" должно быть заполнено');
break;
}
}
return parent::getMessages();
}
示例10: getMessages
/**
* Override default interface
*/
public function getMessages($filter = null)
{
$messages = array();
foreach (parent::getMessages() as $message) {
switch ($message->getType()) {
case 'InvalidCreateAttempt':
$messages[] = 'The record cannot be created because it already exists';
break;
case 'InvalidUpdateAttempt':
$messages[] = 'The record cannot be updated because it already exists';
break;
case 'PresenceOf':
$messages[] = 'The field ' . $message->getField() . ' is mandatory';
break;
}
}
return $messages;
}
示例11: getMessages
/**
* 把信息格式化成我们需要的
*
* @param null $filter
* @return array|\Phalcon\Mvc\MessageInterface[]
*/
public function getMessages($filter = null)
{
$messages = parent::getMessages($filter);
if (empty($messages)) {
return parent::getMessages($filter);
}
$arrayMessages['errors'] = array();
foreach ($messages as $message) {
switch ($message->getType()) {
case 'PresenceOf':
$arrayMessages['errors'][] = array('code' => BaseController::FIELD_REQUIRED, 'field' => $message->getField(), 'message' => $message->getMessage());
break;
case 'Inclusion':
$arrayMessages['errors'][] = array('code' => BaseController::PARAMS_INVALID, 'field' => $message->getField(), 'message' => $message->getMessage());
break;
}
}
return $arrayMessages;
}
示例12: getMessages
public function getMessages($filter = NULL)
{
$messages = array();
foreach (parent::getMessages() as $message) {
switch ($message->getType()) {
case 'PresenceOf':
$messages[] = 'El campo ' . $message->getField() . ' es obligatorio.';
break;
case 'Email':
$messages[] = 'El campo ' . $message->getField() . ' no tiene un formato válido.';
break;
case 'Unique':
$messages[] = 'El campo ' . $message->getField() . ' ya está en uso.';
break;
case 'TooShort':
$messages[] = 'El campo ' . $message->getField() . ' es demasiado corto(min 2 chars).';
break;
case 'TooLong':
$messages[] = 'El campo ' . $message->getField() . ' es demasiado largo(max 30 chars).';
break;
}
}
return $messages;
}
示例13: getMessages
public function getMessages()
{
$messages = array();
$txtmessage = "";
foreach (parent::getMessages() as $message) {
switch ($message->getType()) {
case 'PresenceOf':
switch ($message->getField()) {
case 'name':
$txtmessage = $this->di->get('translate')->_('event.name.required');
break;
case 'start_date':
$txtmessage = $this->di->get('translate')->_('event.start_date.required');
break;
case 'finish_date':
$txtmessage = $this->di->get('translate')->_('event.finish_date.required');
break;
}
$messages[] = $txtmessage;
break;
case 'Unique':
if (is_array($message->getField())) {
$field = implode("-", $message->getField());
} else {
$field = $message->getField();
}
switch ($field) {
case 'name':
$txtmessage = $this->di->get('translate')->_('event.exist');
break;
}
$messages[] = $txtmessage;
break;
case 'ConstraintViolation':
$txtmessage = $this->di->get('translate')->_('event.constraintviolation');
$messages[] = $txtmessage;
break;
case 'Invalid_Dates':
$txtmessage = $this->di->get('translate')->_('event.invalid_dates');
$messages[] = $txtmessage;
break;
}
}
return $messages;
}
示例14: getMessages
public function getMessages($filter = null)
{
$messages = parent::getMessages($filter);
return is_array($messages) ? $messages : [];
}
示例15: onRemoveFailed
protected function onRemoveFailed(Model $item)
{
throw new Exception(ErrorCodes::DATA_FAILED, 'Unable to remove item', ['messages' => $this->_getMessages($item->getMessages()), 'item' => $item->toArray()]);
}