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