add product category crud + model ( termék kategória )
This commit is contained in:
@@ -38,6 +38,7 @@ class AdminMenuStructure{
|
||||
$items[] = ['label' => 'Raktárak', 'url' =>['/warehouse/index']];
|
||||
$items[] = ['label' => 'Kasszák', 'url' =>['/account/index']];
|
||||
$items[] = ['label' => 'Kedvezmények', 'url' => ['/discount/index'] ];
|
||||
$items[] = ['label' => 'Termék kategóriák', 'url' => ['/product-category/index'] ];
|
||||
|
||||
if ( count($items) > 0 ){
|
||||
$userMainMenu = ['label' => 'Beállítások', 'url' => null,
|
||||
|
||||
109
backend/controllers/ProductCategoryController.php
Normal file
109
backend/controllers/ProductCategoryController.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace backend\controllers;
|
||||
|
||||
use Yii;
|
||||
use common\models\ProductCategory;
|
||||
use backend\models\ProductCategorySearch;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
|
||||
/**
|
||||
* ProductCategoryController implements the CRUD actions for ProductCategory model.
|
||||
*/
|
||||
class ProductCategoryController extends Controller
|
||||
{
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
'verbs' => [
|
||||
'class' => VerbFilter::className(),
|
||||
'actions' => [
|
||||
'delete' => ['post'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all ProductCategory models.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
$searchModel = new ProductCategorySearch();
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
|
||||
return $this->render('index', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a single ProductCategory model.
|
||||
* @param integer $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionView($id)
|
||||
{
|
||||
return $this->render('view', [
|
||||
'model' => $this->findModel($id),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new ProductCategory model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionCreate()
|
||||
{
|
||||
$model = new ProductCategory();
|
||||
$model->status = ProductCategory::STATUS_ACTIVE;
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id_product_category]);
|
||||
} else {
|
||||
return $this->render('create', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing ProductCategory model.
|
||||
* If update is successful, the browser will be redirected to the 'view' page.
|
||||
* @param integer $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionUpdate($id)
|
||||
{
|
||||
$model = $this->findModel($id);
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id_product_category]);
|
||||
} else {
|
||||
return $this->render('update', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Finds the ProductCategory model based on its primary key value.
|
||||
* If the model is not found, a 404 HTTP exception will be thrown.
|
||||
* @param integer $id
|
||||
* @return ProductCategory the loaded model
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
protected function findModel($id)
|
||||
{
|
||||
if (($model = ProductCategory::findOne($id)) !== null) {
|
||||
return $model;
|
||||
} else {
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
}
|
||||
}
|
||||
69
backend/models/ProductCategorySearch.php
Normal file
69
backend/models/ProductCategorySearch.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use common\models\ProductCategory;
|
||||
|
||||
/**
|
||||
* ProductCategorySearch represents the model behind the search form about `common\models\ProductCategory`.
|
||||
*/
|
||||
class ProductCategorySearch extends ProductCategory
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id_product_category', 'status'], 'integer'],
|
||||
[['name', 'created_at', 'updated_at'], '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 = ProductCategory::find();
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
$query->andFilterWhere([
|
||||
'id_product_category' => $this->id_product_category,
|
||||
'status' => $this->status,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere(['like', 'name', $this->name]);
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
}
|
||||
26
backend/views/product-category/_form.php
Normal file
26
backend/views/product-category/_form.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model common\models\ProductCategory */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
?>
|
||||
|
||||
<div class="product-category-form">
|
||||
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
|
||||
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<?= $form->field($model, 'status')->checkbox( ['value' => 10, 'label' => Yii::t('common/product_category', "Active") ]) ?>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton($model->isNewRecord ? Yii::t('common/product_category', 'Create') : Yii::t('common/product_category', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
||||
34
backend/views/product-category/_search.php
Normal file
34
backend/views/product-category/_search.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\models\ProductCategorySearch */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
?>
|
||||
|
||||
<div class="product-category-search">
|
||||
|
||||
<?php $form = ActiveForm::begin([
|
||||
'action' => ['index'],
|
||||
'method' => 'get',
|
||||
]); ?>
|
||||
|
||||
<?= $form->field($model, 'id_product_category') ?>
|
||||
|
||||
<?= $form->field($model, 'name') ?>
|
||||
|
||||
<?= $form->field($model, 'status') ?>
|
||||
|
||||
<?= $form->field($model, 'created_at') ?>
|
||||
|
||||
<?= $form->field($model, 'updated_at') ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton(Yii::t('common/product_category', 'Search'), ['class' => 'btn btn-primary']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
||||
21
backend/views/product-category/create.php
Normal file
21
backend/views/product-category/create.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model common\models\ProductCategory */
|
||||
|
||||
$this->title = Yii::t('common/product_category', 'Create Product Category');
|
||||
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/product_category', 'Product Categories'), 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="product-category-create">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
</div>
|
||||
39
backend/views/product-category/index.php
Normal file
39
backend/views/product-category/index.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $searchModel backend\models\ProductCategorySearch */
|
||||
/* @var $dataProvider yii\data\ActiveDataProvider */
|
||||
|
||||
$this->title = Yii::t('common/product_category', 'Product Categories');
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="product-category-index">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
|
||||
|
||||
<p>
|
||||
<?= Html::a(Yii::t('common/product_category', 'Create Product Category'), ['create'], ['class' => 'btn btn-success']) ?>
|
||||
</p>
|
||||
|
||||
<?= GridView::widget([
|
||||
'dataProvider' => $dataProvider,
|
||||
'columns' => [
|
||||
'name',
|
||||
[
|
||||
'attribute' => 'status',
|
||||
'value' => 'statusHuman',
|
||||
],
|
||||
'created_at:datetime',
|
||||
'updated_at:datetime',
|
||||
[
|
||||
'class' => 'yii\grid\ActionColumn',
|
||||
'template' => '{view} {update}'
|
||||
],
|
||||
],
|
||||
]); ?>
|
||||
|
||||
</div>
|
||||
23
backend/views/product-category/update.php
Normal file
23
backend/views/product-category/update.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model common\models\ProductCategory */
|
||||
|
||||
$this->title = Yii::t('common/product_category', 'Update {modelClass}: ', [
|
||||
'modelClass' =>Yii::t('common/product_category', 'Product Category'),
|
||||
]) . ' ' . $model->name;
|
||||
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/product_category', 'Product Categories'), 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id_product_category]];
|
||||
$this->params['breadcrumbs'][] = Yii::t('common/product_category', 'Update');
|
||||
?>
|
||||
<div class="product-category-update">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
</div>
|
||||
44
backend/views/product-category/view.php
Normal file
44
backend/views/product-category/view.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\DetailView;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model common\models\ProductCategory */
|
||||
|
||||
$this->title = $model->name;
|
||||
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/product_category', 'Product Categories'), 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="product-category-view">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<p>
|
||||
<?= Html::a(Yii::t('common/product_category', 'Update'), ['update', 'id' => $model->id_product_category], ['class' => 'btn btn-primary']) ?>
|
||||
<?php
|
||||
/*
|
||||
*
|
||||
echo Html::a(Yii::t('common/product_category', 'Delete'), ['delete', 'id' => $model->id_product_category], [
|
||||
'class' => 'btn btn-danger',
|
||||
'data' => [
|
||||
'confirm' => Yii::t('common/product_category', 'Are you sure you want to delete this item?'),
|
||||
'method' => 'post',
|
||||
],
|
||||
])
|
||||
*/
|
||||
?>
|
||||
</p>
|
||||
|
||||
<?= DetailView::widget([
|
||||
'model' => $model,
|
||||
'attributes' => [
|
||||
'id_product_category',
|
||||
'name',
|
||||
'status',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
],
|
||||
]) ?>
|
||||
|
||||
</div>
|
||||
Reference in New Issue
Block a user