-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdminController.php
117 lines (104 loc) · 2.98 KB
/
AdminController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/**
* Created by PhpStorm.
* User: yidashi
* Date: 2016/12/15
* Time: 下午2:05
*/
namespace common\modules\book\controllers;
use backend\actions\Position;
use common\modules\book\models\Book;
use common\modules\book\models\BookChapter;
use Yii;
use yii\data\ActiveDataProvider;
use yii\web\Controller;
class AdminController extends Controller
{
public function actions()
{
return [
'move-chapter' => [
'class' => Position::className(),
'returnUrl' => request()->referrer,
'findModel' => function($id) {
return BookChapter::findOne($id);
}
]
];
}
public function actionIndex()
{
$dataProvider = new ActiveDataProvider(['query' => Book::find()]);
return $this->render('index', [
'dataProvider' => $dataProvider
]);
}
public function actionCreate()
{
$model = new Book();
if ($model->load(request()->post()) && $model->save()) {
Yii::$app->session->setFlash('success', '保存成功');
return $this->redirect('index');
}
return $this->render('create', [
'model' => $model
]);
}
public function actionView($id)
{
$model = Book::findOne($id);
return $this->render('view', [
'model' => $model
]);
}
public function actionChapter($id)
{
$model = BookChapter::findOne($id);
return $this->render('chapter', [
'model' => $model
]);
}
public function actionUpdate($id)
{
$model = Book::findOne($id);
if ($model->load(request()->post()) && $model->save()) {
Yii::$app->session->setFlash('success', '保存成功');
return $this->redirect('index');
}
return $this->render('update', [
'model' => $model
]);
}
public function actionCreateChapter($id, $chapter_id = 0)
{
$model = new BookChapter();
$model->book_id = $id;
if ($chapter_id > 0) {
$model->pid = $chapter_id;
}
if ($model->load(request()->post()) && $model->save()) {
Yii::$app->session->setFlash('success', '保存成功');
return $this->redirect(['update-chapter', 'id' => $model->id]);
}
return $this->render('create-chapter', [
'model' => $model
]);
}
public function actionUpdateChapter($id)
{
$model = BookChapter::findOne($id);
if ($model->load(request()->post()) && $model->save()) {
Yii::$app->session->setFlash('success', '保存成功');
return $this->refresh();
}
return $this->render('update-chapter', [
'model' => $model
]);
}
public function actionDeleteChapter($id)
{
$model = BookChapter::findOne($id);
$model->delete();
return $this->redirect('index');
}
}