Commit da370fae by dianc

Category Files changes

parent 804166af
......@@ -156,8 +156,7 @@ class CategoryController extends Controller
if ($flag) {
$transaction->commit();
return $this->redirect(['file', 'category_id' => $model->id]);
return $this->redirect(['index', 'category_id' => $model->id]);
}
} catch (Exception $e) {
$transaction->rollBack();
......@@ -189,55 +188,55 @@ class CategoryController extends Controller
}
}
public function actionCreatee()
{
$model = new Category();
$modelFiles = [new CategoryFiles()];
if ($model->load(Yii::$app->request->post())) {
$modelFiles = Model::createMultiple(CategoryFiles::classname());
Model::loadMultiple($modelFiles, Yii::$app->request->post());
// ajax validation
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ArrayHelper::merge(
ActiveForm::validateMultiple($modelFiles),
ActiveForm::validate($model)
);
}
// validate all models
$valid = $model->validate();
$valid = Model::validateMultiple($modelFiles) && $valid;
if ($valid) {
$transaction = \Yii::$app->db->beginTransaction();
try {
if ($flag = $model->save(false)) {
foreach ($modelFiles as $modelFile) {
$modelFile->category_id = $model->id;
if (!($flag = $modelFile->save(false))) {
$transaction->rollBack();
break;
}
}
}
if ($flag) {
$transaction->commit();
return $this->redirect(['file', 'category_id' => $model->id]);
}
} catch (Exception $e) {
$transaction->rollBack();
}
}
}
return $this->render('file', [
'model' => $model,
'modelFiles' => (empty($modelFiles)) ? [new CategoryFiles()] : $modelFiles
]);
}
// public function actionCreatee()
// {
// $model = new Category();
// $modelFiles = [new CategoryFiles()];
// if ($model->load(Yii::$app->request->post())) {
//
// $modelFiles = Model::createMultiple(CategoryFiles::classname());
// Model::loadMultiple($modelFiles, Yii::$app->request->post());
//
// // ajax validation
// if (Yii::$app->request->isAjax) {
// Yii::$app->response->format = Response::FORMAT_JSON;
//
// return ArrayHelper::merge(
// ActiveForm::validateMultiple($modelFiles),
// ActiveForm::validate($model)
// );
// }
//
// // validate all models
// $valid = $model->validate();
// $valid = Model::validateMultiple($modelFiles) && $valid;
//
// if ($valid) {
// $transaction = \Yii::$app->db->beginTransaction();
// try {
// if ($flag = $model->save(false)) {
// foreach ($modelFiles as $modelFile) {
// $modelFile->category_id = $model->id;
// if (!($flag = $modelFile->save(false))) {
// $transaction->rollBack();
// break;
// }
// }
// }
// if ($flag) {
// $transaction->commit();
//
// return $this->redirect(['file', 'category_id' => $model->id]);
// }
// } catch (Exception $e) {
// $transaction->rollBack();
// }
// }
// }
//
// return $this->render('file', [
// 'model' => $model,
// 'modelFiles' => (empty($modelFiles)) ? [new CategoryFiles()] : $modelFiles
// ]);
// }
}
......@@ -27,7 +27,6 @@ $this->params['breadcrumbs'][] = $this->title;
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
// 'id',
'name',
// 'slug',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment