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