<?php $form = ActiveForm::begin(['id' => 'profile-form', 'enableAjaxValidation' => true, 'options' => ['enctype' => 'multipart/form-data']]); ?> <p class="note"><?php echo Module::t('Fields with <span class="required">*</span> are required.'); ?> </p> <?php echo $form->errorSummary([$model, $profile]); ?> <?php $profileFields = Profile::getFields(); if ($profileFields) { foreach ($profileFields as $field) { echo $field->renderField($profile, $form); } } ?> <?php echo $form->field($model, 'username'); ?> <?php echo $form->field($model, 'email'); ?>
/** * Deletes a particular model. * If deletion is successful, the browser will be redirected to the 'index' page. */ public function actionDelete() { if (Yii::$app->request->isPost) { // we only allow deletion via POST request $scheme = get_class(Yii::$app->db->schema); $model = $this->loadModel(); if ($scheme == 'yii\\db\\sqlite\\Schema') { $attr = Profile::getFields(); unset($attr[$model->varname]); $attr = array_keys($attr); $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); $status = true; try { $connection->createCommand("CREATE TEMPORARY TABLE " . Profile::tableName() . "_backup (" . implode(',', $attr) . ")")->execute(); $connection->createCommand("INSERT INTO " . Profile::tableName() . "_backup SELECT " . implode(',', $attr) . " FROM " . Profile::tableName())->execute(); $connection->createCommand("DROP TABLE " . Profile::tableName())->execute(); $connection->createCommand("CREATE TABLE " . Profile::tableName() . " (" . implode(',', $attr) . ")")->execute(); $connection->createCommand("INSERT INTO " . Profile::tableName() . " SELECT " . implode(',', $attr) . " FROM " . Profile::tableName() . "_backup")->execute(); $connection->createCommand("DROP TABLE " . Profile::tableName() . "_backup")->execute(); $transaction->commit(); } catch (Exception $e) { $transaction->rollBack(); $status = false; } if ($status) { $model->delete(); } } else { try { $model->getDb()->createCommand()->dropColumn(Profile::tableName(), $model->varname)->execute(); } catch (\yii\db\Exception $e) { Yii::$app->user->setFlash(Module::ALERT_ERROR, Module::t('Error deleteing Profile table column {column}', ['column' => $model->varname])); } $model->delete(); } // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if (!Yii::$app->request->isAjax) { $this->redirect(['admin']); } } else { throw new HttpException(400, Module::t('Invalid request.')); } }