first commit
This commit is contained in:
24
backend/modules/product/Product.php
Executable file
24
backend/modules/product/Product.php
Executable file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace app\modules\product;
|
||||
|
||||
/**
|
||||
* product module definition class
|
||||
*/
|
||||
class Product extends \yii\base\Module
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public $controllerNamespace = 'app\modules\product\controllers';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
// custom initialization code goes here
|
||||
}
|
||||
}
|
20
backend/modules/product/controllers/DefaultController.php
Executable file
20
backend/modules/product/controllers/DefaultController.php
Executable file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace app\modules\product\controllers;
|
||||
|
||||
use yii\web\Controller;
|
||||
|
||||
/**
|
||||
* Default controller for the `product` module
|
||||
*/
|
||||
class DefaultController extends Controller
|
||||
{
|
||||
/**
|
||||
* Renders the index view for the module
|
||||
* @return string
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('index');
|
||||
}
|
||||
}
|
151
backend/modules/product/controllers/ProductController.php
Executable file
151
backend/modules/product/controllers/ProductController.php
Executable file
@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
namespace app\modules\product\controllers;
|
||||
|
||||
use common\models\Product;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
use yii\web\UploadedFile;
|
||||
|
||||
/**
|
||||
* ProductController implements the CRUD actions for Product model.
|
||||
*/
|
||||
class ProductController extends Controller
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function behaviors()
|
||||
{
|
||||
return array_merge(
|
||||
parent::behaviors(),
|
||||
[
|
||||
'verbs' => [
|
||||
'class' => VerbFilter::className(),
|
||||
'actions' => [
|
||||
'delete' => ['POST'],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all Product models.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => Product::find(),
|
||||
/*
|
||||
'pagination' => [
|
||||
'pageSize' => 50
|
||||
],
|
||||
'sort' => [
|
||||
'defaultOrder' => [
|
||||
'id' => SORT_DESC,
|
||||
]
|
||||
],
|
||||
*/
|
||||
]);
|
||||
|
||||
return $this->render('index', [
|
||||
'dataProvider' => $dataProvider,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a single Product model.
|
||||
* @param int $id ID
|
||||
* @return string
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
public function actionView($id)
|
||||
{
|
||||
return $this->render('view', [
|
||||
'model' => $this->findModel($id),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Product model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return string|\yii\web\Response
|
||||
*/
|
||||
public function actionCreate()
|
||||
{
|
||||
$model = new Product();
|
||||
|
||||
if ($this->request->isPost) {
|
||||
$model->load($this->request->post());
|
||||
if (UploadedFile::getInstance($model, 'photo')) {
|
||||
$model->photo = UploadedFile::getInstance($model, 'photo');
|
||||
$model->photo->saveAs("@frontend/web/images/product/{$model->photo->baseName}.{$model->photo->extension}");
|
||||
$model->photo = '/frontend/web/images/product/' . $model->photo->baseName . $model->photo->extension;
|
||||
}
|
||||
if ($model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
} else {
|
||||
$model->loadDefaultValues();
|
||||
}
|
||||
|
||||
return $this->render('create', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing Product model.
|
||||
* If update is successful, the browser will be redirected to the 'view' page.
|
||||
* @param int $id ID
|
||||
* @return string|\yii\web\Response
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
public function actionUpdate($id)
|
||||
{
|
||||
$model = $this->findModel($id);
|
||||
|
||||
if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
|
||||
return $this->render('update', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an existing Product model.
|
||||
* If deletion is successful, the browser will be redirected to the 'index' page.
|
||||
* @param int $id ID
|
||||
* @return \yii\web\Response
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
public function actionDelete($id)
|
||||
{
|
||||
$this->findModel($id)->delete();
|
||||
|
||||
return $this->redirect(['index']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the Product model based on its primary key value.
|
||||
* If the model is not found, a 404 HTTP exception will be thrown.
|
||||
* @param int $id ID
|
||||
* @return Product the loaded model
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
protected function findModel($id)
|
||||
{
|
||||
if (($model = Product::findOne(['id' => $id])) !== null) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
}
|
12
backend/modules/product/views/default/index.php
Executable file
12
backend/modules/product/views/default/index.php
Executable file
@ -0,0 +1,12 @@
|
||||
<div class="product-default-index">
|
||||
<h1><?= $this->context->action->uniqueId ?></h1>
|
||||
<p>
|
||||
This is the view content for action "<?= $this->context->action->id ?>".
|
||||
The action belongs to the controller "<?= get_class($this->context) ?>"
|
||||
in the "<?= $this->context->module->id ?>" module.
|
||||
</p>
|
||||
<p>
|
||||
You may customize this page by editing the following file:<br>
|
||||
<code><?= __FILE__ ?></code>
|
||||
</p>
|
||||
</div>
|
66
backend/modules/product/views/product/_form.php
Executable file
66
backend/modules/product/views/product/_form.php
Executable file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
use kartik\widgets\FileInput;
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var common\models\Product $model */
|
||||
/** @var yii\widgets\ActiveForm $form */
|
||||
?>
|
||||
|
||||
<div class="product-form">
|
||||
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
|
||||
<?= $form->field($model, 'type')->dropDownList(
|
||||
$model::TypesWithLabels(),
|
||||
[
|
||||
'prompt' => 'Выберите Тип...',
|
||||
]
|
||||
) ?>
|
||||
|
||||
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<?= $form->field($model, 'description')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<?= $form->field($model, 'price')->textInput() ?>
|
||||
|
||||
<?= $form->field($model, 'status')->dropDownList([1 => 'Активен', 0 => 'Не активен'])?>
|
||||
|
||||
<?= $form->field($model, 'photo')->widget(FileInput::class, [
|
||||
'pluginOptions' => [
|
||||
'showZoom' => false,
|
||||
'initialPreview' => [
|
||||
$model->photo != null ? Html::img('@frontend/web/images/product/' . $model->photo, ['class' => 'file-preview-image']) : null,
|
||||
],
|
||||
'overwriteInitial' => true,
|
||||
'showCaption' => false,
|
||||
'showUpload' => false,
|
||||
'showRemove' => true,
|
||||
'showDetails' => true,
|
||||
'browseClass' => 'btn btn-primary btn-block',
|
||||
'browseIcon' => '<i class="fa fa-camera"></i> ',
|
||||
'browseLabel' => 'Выберите фото',
|
||||
],
|
||||
]) ?>
|
||||
|
||||
<?= $form->field($model, 'quantity')->textInput() ?>
|
||||
|
||||
<?= $form->field($model, 'taste')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<?= $form->field($model, 'strength')->dropDownList(
|
||||
$model::TabacooStrengthWithLabel()
|
||||
) ?>
|
||||
|
||||
<?= $form->field($model, 'category_id')->dropDownList(
|
||||
\yii\helpers\ArrayHelper::map(\common\models\Category::find()->asArray()->all(), 'id', 'name')
|
||||
) ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
20
backend/modules/product/views/product/create.php
Executable file
20
backend/modules/product/views/product/create.php
Executable file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var common\models\Product $model */
|
||||
|
||||
$this->title = 'Create Product';
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Products', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="product-create">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
</div>
|
49
backend/modules/product/views/product/index.php
Executable file
49
backend/modules/product/views/product/index.php
Executable file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
use common\models\Product;
|
||||
use yii\helpers\Html;
|
||||
use yii\helpers\Url;
|
||||
use yii\grid\ActionColumn;
|
||||
use yii\grid\GridView;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var yii\data\ActiveDataProvider $dataProvider */
|
||||
|
||||
$this->title = 'Products';
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="product-index">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<p>
|
||||
<?= Html::a('Create Product', ['create'], ['class' => 'btn btn-success']) ?>
|
||||
</p>
|
||||
|
||||
|
||||
<?= GridView::widget([
|
||||
'dataProvider' => $dataProvider,
|
||||
'columns' => [
|
||||
['class' => 'yii\grid\SerialColumn'],
|
||||
|
||||
'id',
|
||||
'type',
|
||||
'name',
|
||||
'description',
|
||||
'price',
|
||||
//'status',
|
||||
//'quantity',
|
||||
//'taste',
|
||||
//'strength',
|
||||
//'category_id',
|
||||
[
|
||||
'class' => ActionColumn::className(),
|
||||
'urlCreator' => function ($action, Product $model, $key, $index, $column) {
|
||||
return Url::toRoute([$action, 'id' => $model->id]);
|
||||
}
|
||||
],
|
||||
],
|
||||
]); ?>
|
||||
|
||||
|
||||
</div>
|
21
backend/modules/product/views/product/update.php
Executable file
21
backend/modules/product/views/product/update.php
Executable file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var common\models\Product $model */
|
||||
|
||||
$this->title = 'Update Product: ' . $model->name;
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Products', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
|
||||
$this->params['breadcrumbs'][] = 'Update';
|
||||
?>
|
||||
<div class="product-update">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
</div>
|
45
backend/modules/product/views/product/view.php
Executable file
45
backend/modules/product/views/product/view.php
Executable file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\DetailView;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var common\models\Product $model */
|
||||
|
||||
$this->title = $model->name;
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Products', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
\yii\web\YiiAsset::register($this);
|
||||
?>
|
||||
<div class="product-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',
|
||||
'type',
|
||||
'name',
|
||||
'description',
|
||||
'price',
|
||||
'status',
|
||||
'quantity',
|
||||
'taste',
|
||||
'strength',
|
||||
'category_id',
|
||||
],
|
||||
]) ?>
|
||||
|
||||
</div>
|
Reference in New Issue
Block a user