本文整理匯總了PHP中yii\base\DynamicModel::addError方法的典型用法代碼示例。如果您正苦於以下問題:PHP DynamicModel::addError方法的具體用法?PHP DynamicModel::addError怎麽用?PHP DynamicModel::addError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類yii\base\DynamicModel
的用法示例。
在下文中一共展示了DynamicModel::addError方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: actionVerify
public function actionVerify()
{
$session = Yii::$app->session;
$urlKey = $this->filter->buildKey('_url');
$urls = $session->get($urlKey);
if (is_array($urls) && isset($urls[0], $urls[1])) {
$route = $urls[0];
$returnUrl = $urls[1];
} else {
throw new \yii\base\InvalidCallException();
}
$key = $this->filter->buildKey($route);
$field = 'f' . substr($key, 0, 10);
$model = new DynamicModel([$field]);
$model->addRule($field, 'required');
if ($model->load(Yii::$app->getRequest()->post()) && $model->validate()) {
if ($this->filter->isValid($model->{$field}, $route)) {
$this->filter->setValid($route);
return Yii::$app->getResponse()->redirect($returnUrl);
} else {
$model->addError($field, $this->filter->message);
}
}
return $this->render($this->viewFile, ['model' => $model, 'field' => $field]);
}
示例2: testBeginHasErrorAndRequired
public function testBeginHasErrorAndRequired()
{
$this->helperModel->addError($this->attributeName, "Error Message");
$this->helperModel->addRule($this->attributeName, 'required');
$expectedValue = '<div class="form-group field-dynamicmodel-attributename required has-error">';
$actualValue = $this->activeField->begin();
$this->assertEquals($expectedValue, $actualValue);
}