Skip to content

Commit 2a91640

Browse files
committed
V1.2
Gii生成了博客原型
1 parent d9d15f9 commit 2a91640

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2326
-2
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
3+
namespace backend\controllers;
4+
5+
use Yii;
6+
use common\models\Adminuser;
7+
use common\models\AdminuserSearch;
8+
use yii\web\Controller;
9+
use yii\web\NotFoundHttpException;
10+
use yii\filters\VerbFilter;
11+
12+
/**
13+
* AdminuserController implements the CRUD actions for Adminuser model.
14+
*/
15+
class AdminuserController extends Controller
16+
{
17+
/**
18+
* @inheritdoc
19+
*/
20+
public function behaviors()
21+
{
22+
return [
23+
'verbs' => [
24+
'class' => VerbFilter::className(),
25+
'actions' => [
26+
'delete' => ['POST'],
27+
],
28+
],
29+
];
30+
}
31+
32+
/**
33+
* Lists all Adminuser models.
34+
* @return mixed
35+
*/
36+
public function actionIndex()
37+
{
38+
$searchModel = new AdminuserSearch();
39+
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
40+
41+
return $this->render('index', [
42+
'searchModel' => $searchModel,
43+
'dataProvider' => $dataProvider,
44+
]);
45+
}
46+
47+
/**
48+
* Displays a single Adminuser model.
49+
* @param integer $id
50+
* @return mixed
51+
*/
52+
public function actionView($id)
53+
{
54+
return $this->render('view', [
55+
'model' => $this->findModel($id),
56+
]);
57+
}
58+
59+
/**
60+
* Creates a new Adminuser model.
61+
* If creation is successful, the browser will be redirected to the 'view' page.
62+
* @return mixed
63+
*/
64+
public function actionCreate()
65+
{
66+
$model = new Adminuser();
67+
68+
if ($model->load(Yii::$app->request->post()) && $model->save()) {
69+
return $this->redirect(['view', 'id' => $model->id]);
70+
} else {
71+
return $this->render('create', [
72+
'model' => $model,
73+
]);
74+
}
75+
}
76+
77+
/**
78+
* Updates an existing Adminuser model.
79+
* If update is successful, the browser will be redirected to the 'view' page.
80+
* @param integer $id
81+
* @return mixed
82+
*/
83+
public function actionUpdate($id)
84+
{
85+
$model = $this->findModel($id);
86+
87+
if ($model->load(Yii::$app->request->post()) && $model->save()) {
88+
return $this->redirect(['view', 'id' => $model->id]);
89+
} else {
90+
return $this->render('update', [
91+
'model' => $model,
92+
]);
93+
}
94+
}
95+
96+
/**
97+
* Deletes an existing Adminuser model.
98+
* If deletion is successful, the browser will be redirected to the 'index' page.
99+
* @param integer $id
100+
* @return mixed
101+
*/
102+
public function actionDelete($id)
103+
{
104+
$this->findModel($id)->delete();
105+
106+
return $this->redirect(['index']);
107+
}
108+
109+
/**
110+
* Finds the Adminuser model based on its primary key value.
111+
* If the model is not found, a 404 HTTP exception will be thrown.
112+
* @param integer $id
113+
* @return Adminuser the loaded model
114+
* @throws NotFoundHttpException if the model cannot be found
115+
*/
116+
protected function findModel($id)
117+
{
118+
if (($model = Adminuser::findOne($id)) !== null) {
119+
return $model;
120+
} else {
121+
throw new NotFoundHttpException('The requested page does not exist.');
122+
}
123+
}
124+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
3+
namespace backend\controllers;
4+
5+
use Yii;
6+
use common\models\Comment;
7+
use common\models\CommentSearch;
8+
use yii\web\Controller;
9+
use yii\web\NotFoundHttpException;
10+
use yii\filters\VerbFilter;
11+
12+
/**
13+
* CommentController implements the CRUD actions for Comment model.
14+
*/
15+
class CommentController extends Controller
16+
{
17+
/**
18+
* @inheritdoc
19+
*/
20+
public function behaviors()
21+
{
22+
return [
23+
'verbs' => [
24+
'class' => VerbFilter::className(),
25+
'actions' => [
26+
'delete' => ['POST'],
27+
],
28+
],
29+
];
30+
}
31+
32+
/**
33+
* Lists all Comment models.
34+
* @return mixed
35+
*/
36+
public function actionIndex()
37+
{
38+
$searchModel = new CommentSearch();
39+
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
40+
41+
return $this->render('index', [
42+
'searchModel' => $searchModel,
43+
'dataProvider' => $dataProvider,
44+
]);
45+
}
46+
47+
/**
48+
* Displays a single Comment model.
49+
* @param integer $id
50+
* @return mixed
51+
*/
52+
public function actionView($id)
53+
{
54+
return $this->render('view', [
55+
'model' => $this->findModel($id),
56+
]);
57+
}
58+
59+
/**
60+
* Creates a new Comment model.
61+
* If creation is successful, the browser will be redirected to the 'view' page.
62+
* @return mixed
63+
*/
64+
public function actionCreate()
65+
{
66+
$model = new Comment();
67+
68+
if ($model->load(Yii::$app->request->post()) && $model->save()) {
69+
return $this->redirect(['view', 'id' => $model->id]);
70+
} else {
71+
return $this->render('create', [
72+
'model' => $model,
73+
]);
74+
}
75+
}
76+
77+
/**
78+
* Updates an existing Comment model.
79+
* If update is successful, the browser will be redirected to the 'view' page.
80+
* @param integer $id
81+
* @return mixed
82+
*/
83+
public function actionUpdate($id)
84+
{
85+
$model = $this->findModel($id);
86+
87+
if ($model->load(Yii::$app->request->post()) && $model->save()) {
88+
return $this->redirect(['view', 'id' => $model->id]);
89+
} else {
90+
return $this->render('update', [
91+
'model' => $model,
92+
]);
93+
}
94+
}
95+
96+
/**
97+
* Deletes an existing Comment model.
98+
* If deletion is successful, the browser will be redirected to the 'index' page.
99+
* @param integer $id
100+
* @return mixed
101+
*/
102+
public function actionDelete($id)
103+
{
104+
$this->findModel($id)->delete();
105+
106+
return $this->redirect(['index']);
107+
}
108+
109+
/**
110+
* Finds the Comment model based on its primary key value.
111+
* If the model is not found, a 404 HTTP exception will be thrown.
112+
* @param integer $id
113+
* @return Comment the loaded model
114+
* @throws NotFoundHttpException if the model cannot be found
115+
*/
116+
protected function findModel($id)
117+
{
118+
if (($model = Comment::findOne($id)) !== null) {
119+
return $model;
120+
} else {
121+
throw new NotFoundHttpException('The requested page does not exist.');
122+
}
123+
}
124+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
3+
namespace backend\controllers;
4+
5+
use Yii;
6+
use common\models\Post;
7+
use common\models\PostSearch;
8+
use yii\web\Controller;
9+
use yii\web\NotFoundHttpException;
10+
use yii\filters\VerbFilter;
11+
12+
/**
13+
* PostController implements the CRUD actions for Post model.
14+
*/
15+
class PostController extends Controller
16+
{
17+
/**
18+
* @inheritdoc
19+
*/
20+
public function behaviors()
21+
{
22+
return [
23+
'verbs' => [
24+
'class' => VerbFilter::className(),
25+
'actions' => [
26+
'delete' => ['POST'],
27+
],
28+
],
29+
];
30+
}
31+
32+
/**
33+
* Lists all Post models.
34+
* @return mixed
35+
*/
36+
public function actionIndex()
37+
{
38+
$searchModel = new PostSearch();
39+
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
40+
41+
return $this->render('index', [
42+
'searchModel' => $searchModel,
43+
'dataProvider' => $dataProvider,
44+
]);
45+
}
46+
47+
/**
48+
* Displays a single Post model.
49+
* @param integer $id
50+
* @return mixed
51+
*/
52+
public function actionView($id)
53+
{
54+
return $this->render('view', [
55+
'model' => $this->findModel($id),
56+
]);
57+
}
58+
59+
/**
60+
* Creates a new Post model.
61+
* If creation is successful, the browser will be redirected to the 'view' page.
62+
* @return mixed
63+
*/
64+
public function actionCreate()
65+
{
66+
$model = new Post();
67+
68+
if ($model->load(Yii::$app->request->post()) && $model->save()) {
69+
return $this->redirect(['view', 'id' => $model->id]);
70+
} else {
71+
return $this->render('create', [
72+
'model' => $model,
73+
]);
74+
}
75+
}
76+
77+
/**
78+
* Updates an existing Post model.
79+
* If update is successful, the browser will be redirected to the 'view' page.
80+
* @param integer $id
81+
* @return mixed
82+
*/
83+
public function actionUpdate($id)
84+
{
85+
$model = $this->findModel($id);
86+
87+
if ($model->load(Yii::$app->request->post()) && $model->save()) {
88+
return $this->redirect(['view', 'id' => $model->id]);
89+
} else {
90+
return $this->render('update', [
91+
'model' => $model,
92+
]);
93+
}
94+
}
95+
96+
/**
97+
* Deletes an existing Post model.
98+
* If deletion is successful, the browser will be redirected to the 'index' page.
99+
* @param integer $id
100+
* @return mixed
101+
*/
102+
public function actionDelete($id)
103+
{
104+
$this->findModel($id)->delete();
105+
106+
return $this->redirect(['index']);
107+
}
108+
109+
/**
110+
* Finds the Post model based on its primary key value.
111+
* If the model is not found, a 404 HTTP exception will be thrown.
112+
* @param integer $id
113+
* @return Post the loaded model
114+
* @throws NotFoundHttpException if the model cannot be found
115+
*/
116+
protected function findModel($id)
117+
{
118+
if (($model = Post::findOne($id)) !== null) {
119+
return $model;
120+
} else {
121+
throw new NotFoundHttpException('The requested page does not exist.');
122+
}
123+
}
124+
}

0 commit comments

Comments
 (0)