本文整理汇总了PHP中yii\db\ActiveRecord::hasErrors方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::hasErrors方法的具体用法?PHP ActiveRecord::hasErrors怎么用?PHP ActiveRecord::hasErrors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\db\ActiveRecord
的用法示例。
在下文中一共展示了ActiveRecord::hasErrors方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processOutput
/**
* Process output. Throw error when not success with unknown reason.
* @param boolean $success
* @param ActiveRecord $model
*
* @return ActiveRecord
* @throws \yii\web\ServerErrorHttpException
*/
protected static function processOutput($success, $model)
{
if (!$success && !$model->hasErrors()) {
throw new ServerErrorHttpException('Error with unknown reason.');
}
return $model;
}
示例2: 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);
}
}