Commit 05f96e6f by dianc

Theme Menu Generation

parent e410c978
......@@ -5,6 +5,7 @@ namespace backend\modules\theme\controllers;
use Yii;
use common\models\Theme;
use backend\modules\theme\models\search\ThemeSearch;
use yii\helpers\Html;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
......@@ -32,6 +33,8 @@ class ThemeController extends Controller
*/
public function actionIndex()
{
$searchModel = new ThemeSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
......@@ -60,15 +63,17 @@ class ThemeController extends Controller
*/
public function actionCreate()
{
$model = new Theme();
$this->layout = '@backend/modules/theme/views/theme/layout.php';
$model = new Theme();
$model->status = $model::STATUS_ACTIVE;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
}
return $this->render('create', [
'model' => $model,
]);
}
}
/**
......@@ -79,6 +84,8 @@ class ThemeController extends Controller
*/
public function actionUpdate($id)
{
$this->layout = '@backend/modules/theme/views/theme/layout.php';
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
......
......@@ -16,7 +16,9 @@ use trntv\filekit\widget\Upload;
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade in active" id="info">
<div class="page-header">
<h3> <?= Yii::t('backend', 'Info') ?> </h3>
</div>
<div class="row">
<div class="col-md-6">
......@@ -41,12 +43,14 @@ use trntv\filekit\widget\Upload;
</div>
<div class="row">
<div class="col-md-6">
<?= $form->field($model, 'image')->widget(
Upload::className(),
[
'url' => ['/file-storage/upload'],
])->label('Image');
?>
</div>
</div>
<div class="row">
......@@ -55,8 +59,10 @@ use trntv\filekit\widget\Upload;
</div>
</div>
<div class="form-group">
<?php echo Html::submitButton($model->isNewRecord ? Yii::t('backend', 'Create') : Yii::t('backend',
'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
</div>
<div class="tab-pane fade in" id="files">
......
......@@ -12,9 +12,6 @@ use wbraganca\dynamicform\DynamicFormWidget;
<?php $form = ActiveForm::begin(['id' => 'dynamic-form']); ?>
<div class="panel panel-default">
<div class="panel-heading">
<h4><i class="glyphicon glyphicon-envelope"></i> Addresses</h4>
</div>
<div class="panel-body">
<?php DynamicFormWidget::begin([
'widgetContainer' => 'dynamicform_wrapper', // required: only alphanumeric characters plus "_" [A-Za-z0-9_]
......
......@@ -11,49 +11,60 @@ use yii\bootstrap\ActiveForm;
<div class="theme-form">
<?php $form = ActiveForm::begin(); ?>
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade in active" id="info">
<div class="page-header">
<h3> <?= Yii::t('backend', 'Info') ?> </h3>
</div>
<div class="row">
<div class="col-md-6">
<?= $form->field($model, 'category_id')->textInput() ?>
<?= $form->field($model, 'category_id')->dropDownList(\common\models\Category::getAllCategories(), ['prompt' => '']) ?>
</div>
</div>
<div class="row">
<div class="col-md-6">
<?= $form->field($model, 'code')->textInput(['maxlength' => true]) ?>
</div>
</div>
<div class="row">
<div class="col-md-6">
<?= $form->field($model, 'slug')->textInput(['maxlength' => true]) ?>
</div>
</div>
<div class="row">
<div class="col-md-6">
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
</div>
</div>
<div class="row">
<div class="col-md-6">
<?= $form->field($model, 'description')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'description')->textarea(['maxlength' => true]) ?>
</div>
</div>
<div class="row">
<div class="col-md-6">
<?= $form->field($model, 'status')->dropDownList($model::statuses(), ['prompt' => '']) ?>
</div>
</div>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('backend', 'Create') : Yii::t('backend', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<div class="tab-pane fade in" id="files">
<div class="page-header">
<h3>Files</h3>
</div>
</div>
<?php ActiveForm::end(); ?>
......
<?php
/* @var $this yii\web\View */
/* @var $model common\models\Theme */
/* @var $modelFiles common\models\ThemeFiles */
$this->params['themeId'] = false;
$this->title = 'Create Theme File';
$this->params['breadcrumbs'][] = ['label' => Yii::t('backend', 'Theme'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="theme-create">
<?= $this->render('..\file\_form', [
'model' => $model,
'modelFiles' => $modelFiles,
]) ?>
</div>
<?php
use yii\widgets\Menu;
/* @var $this yii\web\View */
?>
<?php $this->beginContent('@backend/views/layouts/main.php'); ?>
<?=
Menu::widget([
'items' => [
[
'label' => 'Info',
'url' => $this->params['themeId'] ?
['theme/update', 'id' => $this->params['themeId']]
: ['theme/create'],
],
[
'label' => 'Files',
'url' => $this->params['themeId'] ?
['theme/files', 'id' => $this->params['themeId']]
: '#',
'options' => ['class' => $this->params['themeId'] ? '' : 'disabled']
],
],
'options' => [
'class' => 'nav nav-tabs',
'role' => 'tablist',
'id' => 'theme-form-tab',
],
]);
?>
<div class="tab-content">
<?= $content ?>
</div>
<?php $this->endContent(); ?>
......@@ -7,6 +7,7 @@ use common\models\query\CategoryQuery;
use yii\behaviors\SluggableBehavior;
use yii\behaviors\TimestampBehavior;
use trntv\filekit\behaviors\UploadBehavior;
use yii\helpers\ArrayHelper;
/**
* This is the model class for table "{{%category}}".
......@@ -92,6 +93,16 @@ class Category extends \yii\db\ActiveRecord
];
}
public static function getAllCategories()
{
$models = static::find()->active()->all();
return ArrayHelper::map(
$models,
'id',
'name'
);
}
/**
* @return \yii\db\ActiveQuery
*/
......@@ -116,4 +127,5 @@ class Category extends \yii\db\ActiveRecord
self::STATUS_IN_ACTIVE => Yii::t('common', 'In Active'),
];
}
}
......@@ -3,6 +3,8 @@
namespace common\models;
use Yii;
use yii\behaviors\SluggableBehavior;
use yii\behaviors\TimestampBehavior;
/**
* This is the model class for table "{{%theme}}".
......@@ -38,7 +40,7 @@ class Theme extends \yii\db\ActiveRecord
public function rules()
{
return [
[['category_id', 'code', 'slug', 'name', 'status'], 'required'],
[['category_id', 'code', 'name', 'status'], 'required'],
[['category_id', 'status', 'created_at', 'updated_at'], 'integer'],
[['code', 'slug', 'name'], 'string', 'max' => 32],
[['description'], 'string', 'max' => 512],
......@@ -46,6 +48,22 @@ class Theme extends \yii\db\ActiveRecord
];
}
public function behaviors()
{
return [
[
'class' => SluggableBehavior::className(),
'attribute' => 'name',
],
[
'class' => TimestampBehavior::className(),
'createdAtAttribute' => 'created_at',
'updatedAtAttribute' => 'updated_at'
]
];
}
/**
* @inheritdoc
*/
......
......@@ -2,6 +2,8 @@
namespace common\models\query;
use common\models\Category;
use yii\helpers\ArrayHelper;
/**
* This is the ActiveQuery class for [[Category]].
*
......@@ -9,10 +11,16 @@ namespace common\models\query;
*/
class CategoryQuery extends \yii\db\ActiveQuery
{
/*public function active()
// public function active()
// {
// return $this->andWhere('[[status]]=1');
// }
public function active()
{
return $this->andWhere('[[status]]=1');
}*/
$this->andWhere(['status' => Category::STATUS_ACTIVE]);
return $this;
}
/**
* @inheritdoc
......
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