本文整理匯總了PHP中app\models\Task::addError方法的典型用法代碼示例。如果您正苦於以下問題:PHP Task::addError方法的具體用法?PHP Task::addError怎麽用?PHP Task::addError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\models\Task
的用法示例。
在下文中一共展示了Task::addError方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: validateAttr
public function validateAttr(Task $model)
{
if ($model->task_type == static::TYPE_CHOICE) {
if (!$model['option_A']) {
$model->addError('option_A', Yii::t('app', 'The option_A cannot be blank.'));
}
if (!$model['option_B']) {
$model->addError('option_B', Yii::t('app', 'The option_B cannot be blank.'));
}
if (!$model['answer_choice']) {
$model->addError('answer_choice', Yii::t('app', 'The answer_choice cannot be blank.'));
}
$optionArr = ['A' => $model['option_A'], 'B' => $model['option_B'], 'C' => $model['option_C'], 'D' => $model['option_D']];
$optionArr = array_filter($optionArr);
$choiceArr = $model['answer_choice'];
if (!$this->validateAnswer($optionArr, $choiceArr)) {
$model->addError('answer_choice', Yii::t('app', 'The answer_choice is not correct.'));
}
unset($model['answer_choice']);
$model->option_json = json_encode($optionArr);
$model->answer_json = json_encode($choiceArr);
if ($model->is_timing == static::IS_NOT_TIMING) {
$model->complete_time = '00:00';
}
}
// if ($model->task_type == static::TYPE_SHORT_ANSWER || $model->task_type == static::TYPE_CALCULATION) {
// if (empty($model->answer_json)) {
// $model->addError('answer_json', Yii::t('app', 'The answer_json cannot be blank.'));
// }
// }
if ($model->task_type == static::TYPE_CODING) {
if (empty($model['code_test_one_input'])) {
$model->addError('code_test_one_input', Yii::t('app', 'code_test_one_input cannot be blank.'));
}
if (empty($model['code_test_one_output'])) {
$model->addError('code_test_one_output', Yii::t('app', 'code_test_one_output cannot be blank.'));
}
}
$model->update_time = Common::getTime();
return $model;
}