blobt
5 years ago
15 changed files with 517 additions and 31 deletions
-
53common/models/Category.php
-
74common/models/CategorySearch.php
-
13console/controllers/InitController.php
-
32console/migrations/m190802_072830_add_category.php
-
11console/migrations/sql/add_category.sql
-
3kcadmin/assets/AppAsset.php
-
127kcadmin/controllers/CategoryController.php
-
35kcadmin/views/category/_form.php
-
41kcadmin/views/category/_search.php
-
20kcadmin/views/category/create.php
-
30kcadmin/views/category/index.php
-
21kcadmin/views/category/update.php
-
43kcadmin/views/category/view.php
-
6kcadmin/views/layouts/sidebar.php
-
37kcadmin/web/css/site.css
@ -0,0 +1,53 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace common\models; |
||||
|
|
||||
|
use Yii; |
||||
|
use yii\behaviors\TimestampBehavior; |
||||
|
|
||||
|
/** |
||||
|
* This is the model class for table "category". |
||||
|
* |
||||
|
* @property int $id |
||||
|
* @property string $cat_name |
||||
|
* @property string $icon |
||||
|
* @property int $icon_type |
||||
|
* @property string $description |
||||
|
* @property int $sort_order |
||||
|
* @property int $created_at |
||||
|
* @property int $updated_at |
||||
|
*/ |
||||
|
class Category extends \yii\db\ActiveRecord { |
||||
|
|
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public static function tableName() { |
||||
|
return 'category'; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public function attributeLabels() { |
||||
|
return [ |
||||
|
'id' => 'ID', |
||||
|
'cat_name' => 'Cat Name', |
||||
|
'icon' => 'Icon', |
||||
|
'icon_type' => 'Icon Type', |
||||
|
'description' => 'Description', |
||||
|
'sort_order' => 'Sort Order', |
||||
|
'created_at' => 'Created At', |
||||
|
'updated_at' => 'Updated At', |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
public function behaviors() { |
||||
|
return [ |
||||
|
TimestampBehavior::className() |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,74 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace common\models; |
||||
|
|
||||
|
use yii\base\Model; |
||||
|
use yii\data\ActiveDataProvider; |
||||
|
use common\models\Category; |
||||
|
|
||||
|
/** |
||||
|
* CategorySearch represents the model behind the search form of `\common\models\Category`. |
||||
|
*/ |
||||
|
class CategorySearch extends Category |
||||
|
{ |
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public function rules() |
||||
|
{ |
||||
|
return [ |
||||
|
[['id', 'icon_type', 'sort_order', 'created_at', 'updated_at'], 'integer'], |
||||
|
[['cat_name', 'icon', 'description'], 'safe'], |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public function scenarios() |
||||
|
{ |
||||
|
// bypass scenarios() implementation in the parent class
|
||||
|
return Model::scenarios(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Creates data provider instance with search query applied |
||||
|
* |
||||
|
* @param array $params |
||||
|
* |
||||
|
* @return ActiveDataProvider |
||||
|
*/ |
||||
|
public function search($params) |
||||
|
{ |
||||
|
$query = Category::find(); |
||||
|
|
||||
|
// add conditions that should always apply here
|
||||
|
|
||||
|
$dataProvider = new ActiveDataProvider([ |
||||
|
'query' => $query, |
||||
|
]); |
||||
|
|
||||
|
$this->load($params); |
||||
|
|
||||
|
if (!$this->validate()) { |
||||
|
// uncomment the following line if you do not want to return any records when validation fails
|
||||
|
// $query->where('0=1');
|
||||
|
return $dataProvider; |
||||
|
} |
||||
|
|
||||
|
// grid filtering conditions
|
||||
|
$query->andFilterWhere([ |
||||
|
'id' => $this->id, |
||||
|
'icon_type' => $this->icon_type, |
||||
|
'sort_order' => $this->sort_order, |
||||
|
'created_at' => $this->created_at, |
||||
|
'updated_at' => $this->updated_at, |
||||
|
]); |
||||
|
|
||||
|
$query->andFilterWhere(['like', 'cat_name', $this->cat_name]) |
||||
|
->andFilterWhere(['like', 'icon', $this->icon]) |
||||
|
->andFilterWhere(['like', 'description', $this->description]); |
||||
|
|
||||
|
return $dataProvider; |
||||
|
} |
||||
|
} |
@ -0,0 +1,11 @@ |
|||||
|
DROP TABLE IF EXISTS `category`; |
||||
|
CREATE TABLE `category` ( |
||||
|
`id` int(11) AUTO_INCREMENT PRIMARY KEY, |
||||
|
`cat_name` varchar(64) NOT NULL, |
||||
|
`icon` varchar(64) DEFAULT NULL, |
||||
|
`icon_type` tinyint(1) NOT NULL DEFAULT 1, |
||||
|
`description` text NOT NULL DEFAULT '', |
||||
|
`sort_order` smallint(3) NOT NULL DEFAULT 100, |
||||
|
`created_at` int(11) NOT NULL DEFAULT 0, |
||||
|
`updated_at` int(11) NOT NULL DEFAULT 0 |
||||
|
)ENGINE=INNODB DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; |
@ -0,0 +1,127 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace kcadmin\controllers; |
||||
|
|
||||
|
use Yii; |
||||
|
use common\models\Category; |
||||
|
use common\models\CategorySearch; |
||||
|
use yii\web\Controller; |
||||
|
use yii\web\NotFoundHttpException; |
||||
|
use yii\filters\VerbFilter; |
||||
|
|
||||
|
/** |
||||
|
* CategoryController implements the CRUD actions for Category model. |
||||
|
*/ |
||||
|
class CategoryController extends Controller |
||||
|
{ |
||||
|
/** |
||||
|
* {@inheritdoc} |
||||
|
*/ |
||||
|
public function behaviors() |
||||
|
{ |
||||
|
return [ |
||||
|
'verbs' => [ |
||||
|
'class' => VerbFilter::className(), |
||||
|
'actions' => [ |
||||
|
'delete' => ['POST'], |
||||
|
], |
||||
|
], |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Lists all Category models. |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function actionIndex() |
||||
|
{ |
||||
|
$searchModel = new CategorySearch(); |
||||
|
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); |
||||
|
|
||||
|
return $this->render('index', [ |
||||
|
'searchModel' => $searchModel, |
||||
|
'dataProvider' => $dataProvider, |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Displays a single Category model. |
||||
|
* @param integer $id |
||||
|
* @return mixed |
||||
|
* @throws NotFoundHttpException if the model cannot be found |
||||
|
*/ |
||||
|
public function actionView($id) |
||||
|
{ |
||||
|
return $this->render('view', [ |
||||
|
'model' => $this->findModel($id), |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Creates a new Category model. |
||||
|
* If creation is successful, the browser will be redirected to the 'view' page. |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function actionCreate() |
||||
|
{ |
||||
|
$model = new Category(); |
||||
|
|
||||
|
if ($model->load(Yii::$app->request->post()) && $model->save()) { |
||||
|
return $this->redirect(['view', 'id' => $model->id]); |
||||
|
} |
||||
|
|
||||
|
return $this->render('create', [ |
||||
|
'model' => $model, |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Updates an existing Category model. |
||||
|
* If update is successful, the browser will be redirected to the 'view' page. |
||||
|
* @param integer $id |
||||
|
* @return mixed |
||||
|
* @throws NotFoundHttpException if the model cannot be found |
||||
|
*/ |
||||
|
public function actionUpdate($id) |
||||
|
{ |
||||
|
$model = $this->findModel($id); |
||||
|
|
||||
|
if ($model->load(Yii::$app->request->post()) && $model->save()) { |
||||
|
return $this->redirect(['view', 'id' => $model->id]); |
||||
|
} |
||||
|
|
||||
|
return $this->render('update', [ |
||||
|
'model' => $model, |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Deletes an existing Category model. |
||||
|
* If deletion is successful, the browser will be redirected to the 'index' page. |
||||
|
* @param integer $id |
||||
|
* @return mixed |
||||
|
* @throws NotFoundHttpException if the model cannot be found |
||||
|
*/ |
||||
|
public function actionDelete($id) |
||||
|
{ |
||||
|
$this->findModel($id)->delete(); |
||||
|
|
||||
|
return $this->redirect(['index']); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Finds the Category model based on its primary key value. |
||||
|
* If the model is not found, a 404 HTTP exception will be thrown. |
||||
|
* @param integer $id |
||||
|
* @return Category the loaded model |
||||
|
* @throws NotFoundHttpException if the model cannot be found |
||||
|
*/ |
||||
|
protected function findModel($id) |
||||
|
{ |
||||
|
if (($model = Category::findOne($id)) !== null) { |
||||
|
return $model; |
||||
|
} |
||||
|
|
||||
|
throw new NotFoundHttpException('The requested page does not exist.'); |
||||
|
} |
||||
|
} |
@ -0,0 +1,35 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use yii\helpers\Html; |
||||
|
use yii\widgets\ActiveForm; |
||||
|
|
||||
|
/* @var $this yii\web\View */ |
||||
|
/* @var $model common\models\Category */ |
||||
|
/* @var $form yii\widgets\ActiveForm */ |
||||
|
?>
|
||||
|
|
||||
|
<div class="category-form"> |
||||
|
|
||||
|
<?php $form = ActiveForm::begin(); ?>
|
||||
|
|
||||
|
<?= $form->field($model, 'cat_name')->textInput(['maxlength' => true]) ?>
|
||||
|
|
||||
|
<?= $form->field($model, 'icon')->textInput(['maxlength' => true]) ?>
|
||||
|
|
||||
|
<?= $form->field($model, 'icon_type')->textInput() ?>
|
||||
|
|
||||
|
<?= $form->field($model, 'description')->textarea(['rows' => 6]) ?>
|
||||
|
|
||||
|
<?= $form->field($model, 'sort_order')->textInput() ?>
|
||||
|
|
||||
|
<?= $form->field($model, 'created_at')->textInput() ?>
|
||||
|
|
||||
|
<?= $form->field($model, 'updated_at')->textInput() ?>
|
||||
|
|
||||
|
<div class="form-group"> |
||||
|
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
|
||||
|
</div> |
||||
|
|
||||
|
<?php ActiveForm::end(); ?>
|
||||
|
|
||||
|
</div> |
@ -0,0 +1,41 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use yii\helpers\Html; |
||||
|
use yii\widgets\ActiveForm; |
||||
|
|
||||
|
/* @var $this yii\web\View */ |
||||
|
/* @var $model common\models\CategorySearch */ |
||||
|
/* @var $form yii\widgets\ActiveForm */ |
||||
|
?>
|
||||
|
|
||||
|
<div class="category-search"> |
||||
|
|
||||
|
<?php $form = ActiveForm::begin([ |
||||
|
'action' => ['index'], |
||||
|
'method' => 'get', |
||||
|
]); ?>
|
||||
|
|
||||
|
<?= $form->field($model, 'id') ?>
|
||||
|
|
||||
|
<?= $form->field($model, 'cat_name') ?>
|
||||
|
|
||||
|
<?= $form->field($model, 'icon') ?>
|
||||
|
|
||||
|
<?= $form->field($model, 'icon_type') ?>
|
||||
|
|
||||
|
<?= $form->field($model, 'description') ?>
|
||||
|
|
||||
|
<?php // echo $form->field($model, 'sort_order') ?>
|
||||
|
|
||||
|
<?php // echo $form->field($model, 'created_at') ?>
|
||||
|
|
||||
|
<?php // echo $form->field($model, 'updated_at') ?>
|
||||
|
|
||||
|
<div class="form-group"> |
||||
|
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
|
||||
|
<?= Html::resetButton('Reset', ['class' => 'btn btn-outline-secondary']) ?>
|
||||
|
</div> |
||||
|
|
||||
|
<?php ActiveForm::end(); ?>
|
||||
|
|
||||
|
</div> |
@ -0,0 +1,20 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use yii\helpers\Html; |
||||
|
|
||||
|
/* @var $this yii\web\View */ |
||||
|
/* @var $model common\models\Category */ |
||||
|
|
||||
|
$this->title = 'Create Category'; |
||||
|
$this->params['breadcrumbs'][] = ['label' => 'Categories', 'url' => ['index']]; |
||||
|
$this->params['breadcrumbs'][] = $this->title; |
||||
|
?>
|
||||
|
<div class="category-create"> |
||||
|
|
||||
|
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
|
||||
|
<?= $this->render('_form', [ |
||||
|
'model' => $model, |
||||
|
]) ?>
|
||||
|
|
||||
|
</div> |
@ -0,0 +1,30 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use yii\helpers\Html; |
||||
|
use blobt\grid\GridView; |
||||
|
|
||||
|
|
||||
|
/* @var $this yii\web\View */ |
||||
|
/* @var $searchModel common\models\CategorySearch */ |
||||
|
/* @var $dataProvider yii\data\ActiveDataProvider */ |
||||
|
|
||||
|
$this->title = 'Categories'; |
||||
|
$this->params['breadcrumbs'][] = $this->title; |
||||
|
?>
|
||||
|
<div class="row"> |
||||
|
<div class="col-xs-12"> |
||||
|
<?php |
||||
|
echo GridView::widget([ |
||||
|
'dataProvider' => $dataProvider, |
||||
|
'columns' => [ |
||||
|
'id', |
||||
|
'cat_name', |
||||
|
'icon', |
||||
|
'icon_type', |
||||
|
'description:ntext', |
||||
|
['class' => 'yii\grid\ActionColumn'], |
||||
|
], |
||||
|
]); |
||||
|
?>
|
||||
|
</div> |
||||
|
</div> |
@ -0,0 +1,21 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use yii\helpers\Html; |
||||
|
|
||||
|
/* @var $this yii\web\View */ |
||||
|
/* @var $model common\models\Category */ |
||||
|
|
||||
|
$this->title = 'Update Category: ' . $model->id; |
||||
|
$this->params['breadcrumbs'][] = ['label' => 'Categories', 'url' => ['index']]; |
||||
|
$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]]; |
||||
|
$this->params['breadcrumbs'][] = 'Update'; |
||||
|
?>
|
||||
|
<div class="category-update"> |
||||
|
|
||||
|
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
|
||||
|
<?= $this->render('_form', [ |
||||
|
'model' => $model, |
||||
|
]) ?>
|
||||
|
|
||||
|
</div> |
@ -0,0 +1,43 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use yii\helpers\Html; |
||||
|
use yii\widgets\DetailView; |
||||
|
|
||||
|
/* @var $this yii\web\View */ |
||||
|
/* @var $model common\models\Category */ |
||||
|
|
||||
|
$this->title = $model->id; |
||||
|
$this->params['breadcrumbs'][] = ['label' => 'Categories', 'url' => ['index']]; |
||||
|
$this->params['breadcrumbs'][] = $this->title; |
||||
|
\yii\web\YiiAsset::register($this); |
||||
|
?>
|
||||
|
<div class="category-view"> |
||||
|
|
||||
|
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
|
||||
|
<p> |
||||
|
<?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
|
||||
|
<?= Html::a('Delete', ['delete', 'id' => $model->id], [ |
||||
|
'class' => 'btn btn-danger', |
||||
|
'data' => [ |
||||
|
'confirm' => 'Are you sure you want to delete this item?', |
||||
|
'method' => 'post', |
||||
|
], |
||||
|
]) ?>
|
||||
|
</p> |
||||
|
|
||||
|
<?= DetailView::widget([ |
||||
|
'model' => $model, |
||||
|
'attributes' => [ |
||||
|
'id', |
||||
|
'cat_name', |
||||
|
'icon', |
||||
|
'icon_type', |
||||
|
'description:ntext', |
||||
|
'sort_order', |
||||
|
'created_at', |
||||
|
'updated_at', |
||||
|
], |
||||
|
]) ?>
|
||||
|
|
||||
|
</div> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue