first commit
This commit is contained in:
24
backend/modules/banner/Banner.php
Executable file
24
backend/modules/banner/Banner.php
Executable file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace app\modules\banner;
|
||||
|
||||
/**
|
||||
* banner module definition class
|
||||
*/
|
||||
class Banner extends \yii\base\Module
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public $controllerNamespace = 'app\modules\banner\controllers';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
// custom initialization code goes here
|
||||
}
|
||||
}
|
151
backend/modules/banner/controllers/BannerController.php
Executable file
151
backend/modules/banner/controllers/BannerController.php
Executable file
@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
namespace app\modules\banner\controllers;
|
||||
|
||||
use common\models\Banner;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
use yii\web\UploadedFile;
|
||||
|
||||
/**
|
||||
* BannerController implements the CRUD actions for Banner model.
|
||||
*/
|
||||
class BannerController extends Controller
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function behaviors()
|
||||
{
|
||||
return array_merge(
|
||||
parent::behaviors(),
|
||||
[
|
||||
'verbs' => [
|
||||
'class' => VerbFilter::className(),
|
||||
'actions' => [
|
||||
'delete' => ['POST'],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all Banner models.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => Banner::find(),
|
||||
/*
|
||||
'pagination' => [
|
||||
'pageSize' => 50
|
||||
],
|
||||
'sort' => [
|
||||
'defaultOrder' => [
|
||||
'id' => SORT_DESC,
|
||||
]
|
||||
],
|
||||
*/
|
||||
]);
|
||||
|
||||
return $this->render('index', [
|
||||
'dataProvider' => $dataProvider,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a single Banner 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 Banner model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return string|\yii\web\Response
|
||||
*/
|
||||
public function actionCreate()
|
||||
{
|
||||
$model = new Banner();
|
||||
|
||||
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/banner/{$model->photo->baseName}.{$model->photo->extension}");
|
||||
$model->photo = '/frontend/web/images/banner/' . $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 Banner 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 Banner 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 Banner 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 Banner the loaded model
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
protected function findModel($id)
|
||||
{
|
||||
if (($model = Banner::findOne(['id' => $id])) !== null) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
}
|
20
backend/modules/banner/controllers/DefaultController.php
Executable file
20
backend/modules/banner/controllers/DefaultController.php
Executable file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace app\modules\banner\controllers;
|
||||
|
||||
use yii\web\Controller;
|
||||
|
||||
/**
|
||||
* Default controller for the `banner` module
|
||||
*/
|
||||
class DefaultController extends Controller
|
||||
{
|
||||
/**
|
||||
* Renders the index view for the module
|
||||
* @return string
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('index');
|
||||
}
|
||||
}
|
41
backend/modules/banner/views/banner/_form.php
Executable file
41
backend/modules/banner/views/banner/_form.php
Executable file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
use kartik\widgets\FileInput;
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var common\models\Banner $model */
|
||||
/** @var yii\widgets\ActiveForm $form */
|
||||
?>
|
||||
|
||||
<div class="banner-form">
|
||||
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
|
||||
<?= $form->field($model, 'photo')->widget(FileInput::class, [
|
||||
'pluginOptions' => [
|
||||
'showZoom' => false,
|
||||
'initialPreview' => [
|
||||
$model->photo != null ? Html::img('@web/images/banner/' . $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, 'rating')->textInput() ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
20
backend/modules/banner/views/banner/create.php
Executable file
20
backend/modules/banner/views/banner/create.php
Executable file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var common\models\Banner $model */
|
||||
|
||||
$this->title = 'Create Banner';
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Banners', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="banner-create">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
</div>
|
42
backend/modules/banner/views/banner/index.php
Executable file
42
backend/modules/banner/views/banner/index.php
Executable file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
use common\models\Banner;
|
||||
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 = 'Banners';
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="banner-index">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<p>
|
||||
<?= Html::a('Create Banner', ['create'], ['class' => 'btn btn-success']) ?>
|
||||
</p>
|
||||
|
||||
|
||||
<?= GridView::widget([
|
||||
'dataProvider' => $dataProvider,
|
||||
'columns' => [
|
||||
['class' => 'yii\grid\SerialColumn'],
|
||||
|
||||
'id',
|
||||
'photo',
|
||||
'rating',
|
||||
[
|
||||
'class' => ActionColumn::className(),
|
||||
'urlCreator' => function ($action, Banner $model, $key, $index, $column) {
|
||||
return Url::toRoute([$action, 'id' => $model->id]);
|
||||
}
|
||||
],
|
||||
],
|
||||
]); ?>
|
||||
|
||||
|
||||
</div>
|
21
backend/modules/banner/views/banner/update.php
Executable file
21
backend/modules/banner/views/banner/update.php
Executable file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var common\models\Banner $model */
|
||||
|
||||
$this->title = 'Update Banner: ' . $model->id;
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Banners', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]];
|
||||
$this->params['breadcrumbs'][] = 'Update';
|
||||
?>
|
||||
<div class="banner-update">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
</div>
|
38
backend/modules/banner/views/banner/view.php
Executable file
38
backend/modules/banner/views/banner/view.php
Executable file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\DetailView;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var common\models\Banner $model */
|
||||
|
||||
$this->title = $model->id;
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Banners', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
\yii\web\YiiAsset::register($this);
|
||||
?>
|
||||
<div class="banner-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',
|
||||
'photo',
|
||||
'rating',
|
||||
],
|
||||
]) ?>
|
||||
|
||||
</div>
|
12
backend/modules/banner/views/default/index.php
Executable file
12
backend/modules/banner/views/default/index.php
Executable file
@ -0,0 +1,12 @@
|
||||
<div class="banner-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>
|
Reference in New Issue
Block a user