Commit 11bb6f87 by jomon

code review changes

parent c6ed255b
...@@ -62,20 +62,19 @@ class CategoryController extends Controller ...@@ -62,20 +62,19 @@ class CategoryController extends Controller
*/ */
public function actionCreate() public function actionCreate()
{ {
$model = new Category();
$this->layout = '@backend/modules/theme/views/category/layout.php'; $this->layout = '@backend/modules/theme/views/category/layout.php';
// $model->scenario =
$model = new Category();
$model->status = $model::STATUS_ACTIVE; $model->status = $model::STATUS_ACTIVE;
if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]); return $this->redirect(['view', 'id' => $model->id]);
} else { }
return $this->render('create', [ return $this->render('create', [
'model' => $model, 'model' => $model,
]); ]);
} }
}
/** /**
* Updates an existing Category model. * Updates an existing Category model.
...@@ -85,16 +84,18 @@ class CategoryController extends Controller ...@@ -85,16 +84,18 @@ class CategoryController extends Controller
*/ */
public function actionUpdate($id) public function actionUpdate($id)
{ {
$this->layout = '@backend/modules/theme/views/category/layout.php';
$model = $this->findModel($id); $model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]); return $this->redirect(['view', 'id' => $model->id]);
} else { }
return $this->render('update', [ return $this->render('update', [
'model' => $model, 'model' => $model,
]); ]);
} }
}
/** /**
* Deletes an existing Category model. * Deletes an existing Category model.
......
<?php <?php
use yii\helpers\Html;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $model common\models\Category */ /* @var $model common\models\Category */
$this->params['categoryId'] = false;
$this->title = Yii::t('backend', 'Create {modelClass}', [ $this->title = Yii::t('backend', 'Create {modelClass}', [
'modelClass' => 'Category', 'modelClass' => 'Category',
]); ]);
$this->params['breadcrumbs'][] = ['label' => Yii::t('backend', 'Categories'), 'url' => ['index']]; $this->params['breadcrumbs'][] = ['label' => Yii::t('backend', 'Categories'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title; $this->params['breadcrumbs'][] = $this->title;
?> ?>
<div class="category-create"> <div class="category-create">
<?= $this->render('_form', [ <?= $this->render('_form', [
......
<?php <?php
use yii\widgets\Menu; use yii\widgets\Menu;
use common\models\Category;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
?> ?>
<?php $this->beginContent('@backend/views/layouts/main.php'); ?> <?php $this->beginContent('@backend/views/layouts/main.php'); ?>
<?= <?=
Menu::widget([ Menu::widget([
'items' => [ 'items' => [
['label' => 'Info', 'url' => ['category/create']], [
['label' => 'Files', 'url' => ['category/update', 'id' =>'' ]], 'label' => 'Info',
'url' => $this->params['categoryId'] ? [
'category/update',
'id' => $this->params['categoryId']
] : ['category/create'],
],
[
'label' => 'Files',
'url' => $this->params['categoryId'] ? [
'category/files',
'category_id' => $this->params['categoryId']
] : '#',
'options' => ['class' => $this->params['categoryId'] ? '' : 'disabled']
],
], ],
'options' => [ 'options' => [
'class' => 'nav nav-tabs', 'class' => 'nav nav-tabs',
...@@ -21,7 +33,10 @@ Menu::widget([ ...@@ -21,7 +33,10 @@ Menu::widget([
]); ]);
?> ?>
<div id="myTabContent" class="tab-content"> <div class="tab-content">
<?php echo $content ?>
<?= $content ?>
</div> </div>
<?php $this->endContent(); ?> <?php $this->endContent(); ?>
<?php <?php
use yii\helpers\Html;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $model common\models\Category */ /* @var $model common\models\Category */
$this->params['categoryId'] = $model->id;
$this->title = Yii::t('backend', 'Update {modelClass}: ', [ $this->title = Yii::t('backend', 'Update {modelClass}: ', [
'modelClass' => 'Category', 'modelClass' => 'Category',
]) . ' ' . $model->name; ]) . ' ' . $model->name;
$this->params['breadcrumbs'][] = ['label' => Yii::t('backend', 'Categories'), 'url' => ['index']]; $this->params['breadcrumbs'][] = ['label' => Yii::t('backend', 'Categories'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = Yii::t('backend', 'Update'); $this->params['breadcrumbs'][] = Yii::t('backend', 'Update');
?> ?>
<div class="category-update"> <div class="category-update">
<?= $this->render('_form', [ <?= $this->render('_form', [
......
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