Commit 091d1453 authored by Shakarim Sapa's avatar Shakarim Sapa

- Added CRUD for cases bids

parent 5ba0ba60
......@@ -10,6 +10,109 @@ namespace common\modules\cases\controllers;
use Yii;
use common\components\AdminController;
use common\modules\cases\models\CasesBids;
use yii\data\ActiveDataProvider;
use yii\web\NotFoundHttpException;
class CasesBidsAdminController extends AdminController{
public static function actionsTitles(){
return [
'Manage' => 'Управление подписками',
'Create' => 'Добавление подписки',
'Update' => 'Редактирование подписки',
'View' => 'Просмотр подписки',
'Delete' => 'Удаление подписки',
];
}
/**
* Lists all Bid models.
* @return mixed
*/
public function actionManage()
{
$dataProvider = new ActiveDataProvider([
'query' => CasesBids::find()
]);
return $this->render(
'manage',
[
'dataProvider' => $dataProvider
]
);
}
/**
* @return string|\yii\web\Response
*/
public function actionCreate() {
$model = new CasesBids();
if ($model->load(Yii::$app->request->post())) {
$datetime=new \DateTime();
$model->date=$datetime->format('Y-m-d H:i:s');
if ($model->save())
return $this->redirect([
'manage'
]);
}
$form = new \common\components\BaseForm('/common/modules/blog/forms/BidForm', $model);
return $this->render(
'create',
[
'form' => $form
]
);
}
/**
* @param $id
* @return string|\yii\web\Response
*/
public function actionUpdate($id){
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post())) {
$datetime=new \DateTime();;
$model->date=$datetime->format('Y-m-d H:i:s');
if ($model->save())
return $this->redirect([
'manage'
]);
} else {
$form = new \common\components\BaseForm('/common/modules/blog/forms/BidForm', $model);
return $this->render(
'update',
[
'form' => $form
]
);
}
}
/**
* @param $id
* @return \yii\web\Response
*/
public function actionDelete($id){
$this->findModel($id)->delete();
return $this->redirect(['manage']);
}
/**
* @param $id
* @return null|CasesBids
* @throws NotFoundHttpException
*/
protected function findModel($id)
{
if (($model = CasesBids::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
\ No newline at end of file
<?php
return [
'activeForm' => [
'id' => 'trigger-form'
],
'elements' => [
'email' => [
'type' => 'text',
'class' => 'form-control',
]
],
'buttons' => [
'submit' => ['type' => 'submit', 'value' => 'Cохранить']
]
];
\ No newline at end of file
<?php
echo $form->out;
\ No newline at end of file
<?php
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */
?>
<div class="blog-bid-index">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a('Добавить подписку', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'email',
'date:datetime',
[
'class' => 'yii\grid\ActionColumn',
'template' => '{update}{delete}',
],
],
]); ?>
</div>
<?php
echo $form->out;
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment