本文整理汇总了PHP中app\models\Student::addError方法的典型用法代码示例。如果您正苦于以下问题:PHP Student::addError方法的具体用法?PHP Student::addError怎么用?PHP Student::addError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Student
的用法示例。
在下文中一共展示了Student::addError方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionRegistration
public function actionRegistration($role = '')
{
if (!\Yii::$app->user->isGuest) {
$this->redirect(\Yii::$app->user->getReturnUrl());
}
if ($role == '') {
return $this->render('registration');
}
$model = new User();
$role_model = new Company();
$model->role = User::ROLE_COMPANY;
if ($role != 'company') {
//Student registration
$role = 'student';
$role_model = new Student();
$model->role = User::ROLE_STUDENT;
}
if ($model->load(Yii::$app->request->post()) && $role_model->load(Yii::$app->request->post()) && $model->register()) {
if ($role == 'student') {
$role_model->idUser = $model->id;
if ($role_model->save()) {
return $this->render('registration_student_success', ['model' => $model]);
}
} else {
$role_model->idUser = $model->id;
//Upload logo
if (isset($_FILES['Company']) && $_FILES['Company']['name']['logo_path'] != "") {
if (!in_array($_FILES['Company']['type']['logo_path'], $this->image_array)) {
$role_model->addError('logo_path', 'Доступные расширения для файла: jpg, gif, png.');
} else {
$rnd = rand(0, 9999);
$uploadedFile = UploadedFile::getInstance($role_model, 'logo_path');
$fileName = 'files/' . $rnd . '_' . $uploadedFile->name;
$role_model->logo_path = $fileName;
$uploadedFile->saveAs($fileName);
}
}
if ($role_model->save()) {
return $this->render('registration_company_success', ['model' => $model]);
}
}
}
return $this->render('registration_' . $role, ['model' => $model, 'role_model' => $role_model]);
}