Permalink
Browse files

Изменение и удаление задач

  • Loading branch information...
sabian committed Jan 10, 2016
1 parent 189ca50 commit 2157ef21c754c40b562aa64bef59a4b96c93587b
Showing with 85 additions and 0 deletions.
  1. +61 −0 controllers/TodoBackendController.php
  2. +24 −0 views/todoBackend/update.php
@@ -7,6 +7,16 @@
*/
class TodoBackendController extends BackController
{
public function filters()
{
return CMap::mergeArray(
parent::filters(),
[
'postOnly + delete',
]
);
}
public function actionIndex()
{
$model = new Todo('search');
@@ -38,4 +48,55 @@ public function actionCreate()
$this->render('create', ['model' => $model]);
}
public function actionUpdate($id)
{
$model = $this->loadModel($id);
if ($data = Yii::app()->getRequest()->getPost('Todo')) {
$model->setAttributes($data);
if ($model->update()) {
Yii::app()->user->setFlash(YFlashMessages::SUCCESS_MESSAGE, 'Задача успешно обновлена');
$submitType = Yii::app()->getRequest()->getPost('submit-type');
if (isset($submitType)) {
$this->redirect([$submitType]);
} else {
$this->redirect(['update', 'id' => $model->id]);
}
}
}
$this->render('update', ['model' => $model]);
}
public function actionDelete($id)
{
if ($this->loadModel($id)->delete()) {
Yii::app()->user->setFlash(YFlashMessages::SUCCESS_MESSAGE, 'Задача успешно удалена');
if (!Yii::app()->getRequest()->getParam('ajax')) {
$this->redirect((array)Yii::app()->getRequest()->getPost('returnUrl', 'index'));
}
}
}
/**
* @param $id
* @return Todo
* @throws CHttpException
*/
private function loadModel($id)
{
$model = Todo::model()->findByPk($id);
if ($model === null) {
throw new CHttpException(404, 'Запрошенная страница не найдена.');
}
return $model;
}
}
@@ -0,0 +1,24 @@
<?php
/**
* @var $model Todo
*/
$this->pageTitle = 'ToDo - Изменение задачи';
$this->breadcrumbs = [
'Список задач' => ['/todo/todoBackend/index'],
$this->pageTitle
];
$this->menu = [
['icon' => 'fa fa-fw fa-list-alt', 'label' => 'Список задач', 'url' => ['/todo/todoBackend/index']],
['icon' => 'fa fa-fw fa-plus-square', 'label' => 'Создать задачу', 'url' => ['/todo/todoBackend/create']],
['icon' => 'fa fa-fw fa-pencil', 'label' => 'Изменить задачу', 'url' => ['/todo/todoBackend/update', 'id' => $model->id]],
];
?>
<div class="page-header">
<h1>Изменение задачи <small>№<?= $model->id ?></small></h1>
</div>
<?= $this->renderPartial('_form', ['model' => $model]); ?>

0 comments on commit 2157ef2

Please sign in to comment.