Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taskonsite-архив-перенесен
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitry Korolev
taskonsite-архив-перенесен
Commits
66d011d4
Commit
66d011d4
authored
Apr 28, 2016
by
Shakarim Sapa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Добавлен контроллер для подписок на кейсы;
parent
278ea0f7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
2 deletions
+54
-2
common/modules/cases/controllers/DefaultController.php
common/modules/cases/controllers/DefaultController.php
+54
-2
No files found.
common/modules/cases/controllers/DefaultController.php
View file @
66d011d4
...
@@ -2,13 +2,25 @@
...
@@ -2,13 +2,25 @@
namespace
common\modules\cases\controllers
;
namespace
common\modules\cases\controllers
;
use
yii\web\Controller
;
use
Yii
;
use
common\components\BaseController
;
use
common\modules\cases\models\CasesBids
;
use
yii\web\NotFoundHttpException
;
use
yii\web\Response
;
use
yii\widgets\ActiveForm
;
/**
/**
* Default controller for the `Cases` module
* Default controller for the `Cases` module
*/
*/
class
DefaultController
extends
Controller
class
DefaultController
extends
Base
Controller
{
{
public
static
function
actionsTitles
()
{
return
[
'Add'
=>
'Subscribe to blog'
];
}
/**
/**
* Renders the index view for the module
* Renders the index view for the module
* @return string
* @return string
...
@@ -17,4 +29,44 @@ class DefaultController extends Controller
...
@@ -17,4 +29,44 @@ class DefaultController extends Controller
{
{
return
$this
->
render
(
'index'
);
return
$this
->
render
(
'index'
);
}
}
/**
* @return array
* @throws NotFoundHttpException
* @throws \Exception
*/
public
function
actionAdd
(){
Yii
::
$app
->
response
->
format
=
Response
::
FORMAT_JSON
;
// Получили дату
$date
=
new
\DateTime
();
// Создали модель
$model
=
new
CasesBids
();
// Получили и переопределили данные из формы
if
(
Yii
::
$app
->
request
->
isAjax
&&
$model
->
load
(
Yii
::
$app
->
request
->
post
()))
{
// Переопределили дату
$model
->
date
=
$date
->
format
(
'Y-m-d H:i:s'
);
// Открыли транзакцию
$transaction
=
Yii
::
$app
->
db
->
beginTransaction
();
// Пытаемся сохранить запись в базе
try
{
// Если запись успешна
if
(
$model
->
save
())
{
// Коммитим транзакцию
$transaction
->
commit
();
// Возвращаем результат
return
[
'success'
=>
true
];
}
else
{
// В противном случае возвращаем форму с ошибками
return
ActiveForm
::
validate
(
$model
);
}
}
catch
(
\Exception
$e
)
{
// Обрабатываем исключение
$transaction
->
rollBack
();
throw
$e
;
}
}
else
{
// Если это не ajax запрос, возвращаем ошибку
throw
new
NotFoundHttpException
(
'The requested page does not exist.'
);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment