-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
437 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<?php | ||
|
||
namespace frontend\controllers; | ||
|
||
use Yii; | ||
use common\models\Post; | ||
use common\models\PostSearch; | ||
use yii\web\Controller; | ||
use yii\web\NotFoundHttpException; | ||
use yii\filters\VerbFilter; | ||
|
||
/** | ||
* PostController implements the CRUD actions for Post model. | ||
*/ | ||
class PostController extends Controller | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function behaviors() | ||
{ | ||
return [ | ||
'verbs' => [ | ||
'class' => VerbFilter::className(), | ||
'actions' => [ | ||
'delete' => ['POST'], | ||
], | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* Lists all Post models. | ||
* @return mixed | ||
*/ | ||
public function actionIndex() | ||
{ | ||
$searchModel = new PostSearch(); | ||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); | ||
|
||
return $this->render('index', [ | ||
'searchModel' => $searchModel, | ||
'dataProvider' => $dataProvider, | ||
]); | ||
} | ||
|
||
/** | ||
* Displays a single Post model. | ||
* @param integer $id | ||
* @return mixed | ||
*/ | ||
public function actionView($id) | ||
{ | ||
return $this->render('view', [ | ||
'model' => $this->findModel($id), | ||
]); | ||
} | ||
|
||
/** | ||
* Creates a new Post model. | ||
* If creation is successful, the browser will be redirected to the 'view' page. | ||
* @return mixed | ||
*/ | ||
public function actionCreate() | ||
{ | ||
$model = new Post(); | ||
|
||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | ||
return $this->redirect(['view', 'id' => $model->id]); | ||
} else { | ||
return $this->render('create', [ | ||
'model' => $model, | ||
]); | ||
} | ||
} | ||
|
||
/** | ||
* Updates an existing Post model. | ||
* If update is successful, the browser will be redirected to the 'view' page. | ||
* @param integer $id | ||
* @return mixed | ||
*/ | ||
public function actionUpdate($id) | ||
{ | ||
$model = $this->findModel($id); | ||
|
||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | ||
return $this->redirect(['view', 'id' => $model->id]); | ||
} else { | ||
return $this->render('update', [ | ||
'model' => $model, | ||
]); | ||
} | ||
} | ||
|
||
/** | ||
* Deletes an existing Post model. | ||
* If deletion is successful, the browser will be redirected to the 'index' page. | ||
* @param integer $id | ||
* @return mixed | ||
*/ | ||
public function actionDelete($id) | ||
{ | ||
$this->findModel($id)->delete(); | ||
|
||
return $this->redirect(['index']); | ||
} | ||
|
||
/** | ||
* Finds the Post model based on its primary key value. | ||
* If the model is not found, a 404 HTTP exception will be thrown. | ||
* @param integer $id | ||
* @return Post the loaded model | ||
* @throws NotFoundHttpException if the model cannot be found | ||
*/ | ||
protected function findModel($id) | ||
{ | ||
if (($model = Post::findOne($id)) !== null) { | ||
return $model; | ||
} else { | ||
throw new NotFoundHttpException('The requested page does not exist.'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
use yii\helpers\Html; | ||
use yii\widgets\ActiveForm; | ||
|
||
/* @var $this yii\web\View */ | ||
/* @var $model common\models\Post */ | ||
/* @var $form yii\widgets\ActiveForm */ | ||
?> | ||
|
||
<div class="post-form"> | ||
|
||
<?php $form = ActiveForm::begin(); ?> | ||
|
||
<?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?> | ||
|
||
<?= $form->field($model, 'content')->textarea(['rows' => 6]) ?> | ||
|
||
<?= $form->field($model, 'tags')->textarea(['rows' => 6]) ?> | ||
|
||
<?= $form->field($model, 'status')->textInput() ?> | ||
|
||
<?= $form->field($model, 'create_time')->textInput() ?> | ||
|
||
<?= $form->field($model, 'update_time')->textInput() ?> | ||
|
||
<?= $form->field($model, 'author_id')->textInput() ?> | ||
|
||
<div class="form-group"> | ||
<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | ||
</div> | ||
|
||
<?php ActiveForm::end(); ?> | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
use yii\helpers\Html; | ||
?> | ||
|
||
<div class="post"> | ||
<div class="title"> | ||
<h2><a href="<?= $model->url;?>"><?= Html::encode($model->title);?></a></h2> | ||
|
||
<div class="author"> | ||
<span class="glyphicon glyphicon-time" aria-hidden="true"></span><em><?= date('Y-m-d H:i:s',$model->create_time)." ";?></em> | ||
<span class="glyphicon glyphicon-user" aria-hidden="true"></span><em><?= Html::encode($model->author->nickname);?></em> | ||
</div> | ||
</div> | ||
|
||
<br> | ||
<div class="content"> | ||
<?= $model->beginning;?> | ||
</div> | ||
|
||
<br> | ||
<div class="nav"> | ||
<span class="glyphicon glyphicon-tag" aria-hidden="true"></span> | ||
<?= implode(', ',$model->tagLinks);?> | ||
<br> | ||
<?= Html::a("评论 ({$model->commentCount})",$model->url.'#comments')?> | 最后修改于 <?= date('Y-m-s H:i:s',$model->update_time);?> | ||
</div> | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
use yii\helpers\Html; | ||
use yii\widgets\ActiveForm; | ||
|
||
/* @var $this yii\web\View */ | ||
/* @var $model common\models\PostSearch */ | ||
/* @var $form yii\widgets\ActiveForm */ | ||
?> | ||
|
||
<div class="post-search"> | ||
|
||
<?php $form = ActiveForm::begin([ | ||
'action' => ['index'], | ||
'method' => 'get', | ||
]); ?> | ||
|
||
<?= $form->field($model, 'id') ?> | ||
|
||
<?= $form->field($model, 'title') ?> | ||
|
||
<?= $form->field($model, 'content') ?> | ||
|
||
<?= $form->field($model, 'tags') ?> | ||
|
||
<?= $form->field($model, 'status') ?> | ||
|
||
<?php // echo $form->field($model, 'create_time') ?> | ||
|
||
<?php // echo $form->field($model, 'update_time') ?> | ||
|
||
<?php // echo $form->field($model, 'author_id') ?> | ||
|
||
<div class="form-group"> | ||
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?> | ||
<?= Html::resetButton('Reset', ['class' => 'btn btn-default']) ?> | ||
</div> | ||
|
||
<?php ActiveForm::end(); ?> | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
use yii\helpers\Html; | ||
|
||
|
||
/* @var $this yii\web\View */ | ||
/* @var $model common\models\Post */ | ||
|
||
$this->title = 'Create Post'; | ||
$this->params['breadcrumbs'][] = ['label' => 'Posts', 'url' => ['index']]; | ||
$this->params['breadcrumbs'][] = $this->title; | ||
?> | ||
<div class="post-create"> | ||
|
||
<h1><?= Html::encode($this->title) ?></h1> | ||
|
||
<?= $this->render('_form', [ | ||
'model' => $model, | ||
]) ?> | ||
|
||
</div> |
Oops, something went wrong.