/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Platforms(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Platforms'])) { $foto = $_FILES["image"]; $nome = $_POST['Platforms']['name']; $nome_imagem = "image_" . $nome . ".png"; //$caminho_imagem = "C:/xampp/htdocs/mtcontrool/fotos/" . $nome_imagem; if (move_uploaded_file($foto["tmp_name"], "C:/xampp/htdocs/mtcontrool/fotos/" . $nome_imagem)) { $model->setAttribute('image', $nome_imagem); // carregou o arquivo com sucesso } else { print "Possivel ataque de upload! Aqui esta alguma informação:\n"; print_r($_FILES); } $model->attributes = $_POST['Platforms']; $model->setRelationRecords('characteristic', is_array(@$_POST['Characteristic']) ? $_POST['Characteristic'] : array()); if ($model->save()) { // var_dump(realpath('/fotos')); Yii::app()->user->setFlash('success', "Platform saved with sucess!"); } } $this->render('create', array('model' => $model)); }
public function actionSigninPlatform() { if (!Yii::app()->user->isGuest) { $this->redirect('/'); } $user = new Users('signin'); if (isset($_POST['Users'])) { $user->attributes = $_POST['Users']; } $user->role = Users::ROLE_PLATFORM; $user->status = Users::STATUS_MODERATION; $platform = new Platforms('signin'); if (isset($_POST['Platforms'])) { $platform->attributes = $_POST['Platforms']; } $platform->is_active = 0; if (isset($_POST['Users']) && isset($_POST['Platforms'])) { $user->validate(); $platform->validate(); if (!$user->hasErrors() && !$platform->hasErrors()) { $transaction = $user->getDbConnection()->beginTransaction(); if ($user->save(false)) { $platform->user_id = $user->id; if ($platform->save(false)) { SMail::sendMail(Yii::app()->params['registrationEmail'], 'Регистрация пользователя ' . $user->email, 'SignInRequest', array('user' => $user)); $transaction->commit(); $this->redirect(array('users/signinSuccess')); } } $transaction->rollback(); } } $this->render('signin_platform', array('user' => $user, 'platform' => $platform)); }