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