本文整理汇总了PHP中yii\db\ActiveRecord::getErrors方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::getErrors方法的具体用法?PHP ActiveRecord::getErrors怎么用?PHP ActiveRecord::getErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\db\ActiveRecord
的用法示例。
在下文中一共展示了ActiveRecord::getErrors方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* @inheritdoc
*/
public function run()
{
foreach ($this->model->getErrors() as $attribute => $messages) {
foreach ($messages as $key => $message) {
$this->options['id'] = 'error-' . $attribute . '-' . $key;
echo \yii\bootstrap\Alert::widget(['body' => $message, 'closeButton' => $this->closeButton, 'options' => $this->options]);
}
}
}
示例2: addErrorMessagesFromModel
/**
* @param ActiveRecord $model
*/
public function addErrorMessagesFromModel(ActiveRecord $model)
{
foreach ($model->getErrors() as $fieldWithErrors) {
foreach ($fieldWithErrors as $error) {
$this->addMessage(null, $error, Message::ALERT);
}
}
}
示例3: populateErrors
/**
* @param \yii\db\ActiveRecord $Model
* @param string $default_attribute
*/
public function populateErrors(\yii\db\ActiveRecord $Model, $default_attribute)
{
$errors = $Model->getErrors();
foreach ($errors as $key => $messages) {
$attribute = $key;
if (false === $this->hasProperty($attribute)) {
if (!method_exists($this, 'hasAttribute')) {
$attribute = $default_attribute;
} elseif (false === $this->hasAttribute($attribute)) {
$attribute = $default_attribute;
}
}
foreach ($messages as $mes) {
$this->addError($attribute, $mes);
}
}
}
示例4: populateErrors
/**
* @param ActiveRecord $model
* @param string $defaultAttribute
* @param array $attributesMap
*/
public function populateErrors(ActiveRecord $model, $defaultAttribute, $attributesMap = [])
{
/** @var Model $this */
$errors = $model->getErrors();
foreach ($errors as $attribute => $messages) {
$attribute = isset($attributesMap[$attribute]) ? $attributesMap[$attribute] : $attribute;
if (false === $this->hasProperty($attribute)) {
if (!method_exists($this, 'hasAttribute')) {
$attribute = $defaultAttribute;
} elseif (false === $this->hasAttribute($attribute)) {
$attribute = $defaultAttribute;
}
}
foreach ($messages as $mes) {
$this->addError($attribute, $mes);
}
}
}
示例5: throwInvalidModelException
/**
* Converts the model validation errors to a readable format an throws it as an exception
* @param ActiveRecord $model
* @throws Exception
*/
protected function throwInvalidModelException($model)
{
$errorMessage = Yii::t('language', 'Invalid model "{model}":', ['model' => $model->className()]);
foreach ($model->getErrors() as $attribute => $errors) {
$errorMessage .= "\n {$attribute}: " . join(', ', $errors);
}
throw new Exception($errorMessage);
}
示例6: runCrudAction
/**
* Run Create/Read/Update/Delete action
*
* Set error flash and throw Exception, if action failed
* Return nothing if action succeed
*
* @param \yii\db\ActiveRecord|\yii\db\ActiveRecord[] $model
* @return void
* @throws \Exception
*/
protected function runCrudAction($model)
{
if ($model instanceof Model) {
if (!call_user_func([$model, $this->modelAction])) {
if ($model->hasErrors()) {
$this->flashError = [];
foreach ($model->getErrors() as $errors) {
$this->flashError = array_merge($this->flashError, $errors);
}
}
throw new \Exception($this->flashError ? VarDumper::dumpAsString($this->flashError) : 'Unknown error');
}
return;
}
foreach ($model as $concreteModel) {
$this->runCrudAction($concreteModel);
}
}
示例7: chainDelete
/**
* @param ActiveRecord $model
* @return ActiveRecord
* @throws \yii\web\ServerErrorHttpException
*/
protected function chainDelete($model)
{
if (!$model->delete()) {
if (YII_DEBUG) {
Yii::$app->response->statusCode = 500;
Yii::$app->response->format = Response::FORMAT_JSON;
var_dump($model->getErrors());
Yii::$app->end();
}
throw new ServerErrorHttpException('Do not able to save the model.');
}
return $model;
}
示例8: addValidationErrors
/**
* @param \yii\db\ActiveRecord $model
*/
public function addValidationErrors($model)
{
$keyValue = $this->composeKey($model->getPrimaryKey(true));
$this->_errors['validation'][$keyValue] = $model->getErrors();
}