本文整理匯總了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);
}
}