-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
781 additions
and
435 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: yidashi | ||
* Date: 2016/12/15 | ||
* Time: 下午2:05 | ||
*/ | ||
|
||
namespace backend\controllers; | ||
|
||
|
||
use common\models\Book; | ||
use common\models\BookChapter; | ||
use yii\data\ActiveDataProvider; | ||
use yii\web\Controller; | ||
use Yii; | ||
|
||
class BookController extends Controller | ||
{ | ||
|
||
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 | ||
]); | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: yidashi | ||
* Date: 2016/12/16 | ||
* Time: 下午5:42 | ||
*/ | ||
|
||
use yii\helpers\Html; | ||
use yii\helpers\Markdown; | ||
use backend\widgets\ActiveForm; | ||
|
||
?> | ||
|
||
<div class="box box-solid"> | ||
<div class="box-body"> | ||
<?php $form = Activeform::begin() ?> | ||
<?= $form->field($model, 'book_name') ?> | ||
|
||
<?= $form->field($model, 'book_cover')->widget(\common\widgets\upload\SingleWidget::className()) ?> | ||
|
||
<?= $form->field($model, 'book_description')->widget(\common\widgets\editormd\Editormd::className(), ['clientOptions' => ['watch' => true, 'height' => 1000]]) ?> | ||
|
||
<div class="form-group"> | ||
<?= Html::submitButton('保存', ['class' => 'btn bg-maroon btn-flat btn-block']) ?> | ||
</div> | ||
<?php ActiveForm::end() ?> | ||
</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,23 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: yidashi | ||
* Date: 2016/12/16 | ||
* Time: 下午5:50 | ||
*/ | ||
|
||
use yii\helpers\Html; | ||
use yii\helpers\HtmlPurifier; | ||
use yii\helpers\Markdown; | ||
use backend\widgets\ActiveForm; | ||
|
||
?> | ||
|
||
<?php $form = Activeform::begin() ?> | ||
<?= $form->field($model, 'chapter_name') ?> | ||
|
||
<?= $form->field($model, 'chapter_body')->widget(\common\widgets\editormd\Editormd::className(), ['clientOptions' => ['watch' => true, 'height' => 1000]]) ?> | ||
<div class="form-group"> | ||
<?= Html::submitButton('保存', ['class' => 'btn bg-maroon btn-flat btn-block']) ?> | ||
</div> | ||
<?php ActiveForm::end() ?> |
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,32 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: yidashi | ||
* Date: 2016/12/15 | ||
* Time: 下午3:14 | ||
*/ | ||
|
||
/** | ||
* @var \yii\web\View $this | ||
* @var common\models\BookChapter $model | ||
*/ | ||
?> | ||
<div class="row"> | ||
<div class="col-md-3"> | ||
<?= \frontend\widgets\SideNavWidget::widget([ | ||
'items' => $model->book->getUpdateMenuItems() | ||
]) ?> | ||
|
||
<?= \yii\helpers\Html::a('新增章节', ['/book/create-chapter', 'id' => $model->book->id], ['class' => 'btn bg-maroon btn-lg']) ?> | ||
<?php if (!$model->isNewRecord): ?> | ||
<?= \yii\helpers\Html::a('新增子章节', ['/book/create-chapter', 'id' => $model->book->id, 'chapter_id' => $model->id], ['class' => 'btn bg-maroon btn-lg']) ?> | ||
<?php endif; ?> | ||
</div> | ||
<div class="col-md-9"> | ||
<div class="box box-solid"> | ||
<div class="box-body"> | ||
<?= $content ?> | ||
</div> | ||
</div> | ||
</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,27 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: yidashi | ||
* Date: 2016/12/15 | ||
* Time: 下午2:20 | ||
*/ | ||
/** | ||
* @var \yii\web\View $this | ||
* @var \common\models\BookChapter $model | ||
*/ | ||
|
||
use yii\helpers\Html; | ||
use yii\helpers\HtmlPurifier; | ||
use yii\helpers\Markdown; | ||
|
||
$this->title = $model->chapter_name; | ||
$this->params['breadcrumbs'][] = ['label' => '书', 'url' => ['/book/index']]; | ||
$this->params['breadcrumbs'][] = ['label' => $model->book->book_name, 'url' => ['/book/view', 'id' => $model->book->id]]; | ||
$this->params['breadcrumbs'][] = Html::encode($model->chapter_name); | ||
?> | ||
<?php $this->beginContent('@backend/views/book/_layout.php', ['book' => $model->book]) ?> | ||
<div class="view-title"> | ||
<h1><?= Html::encode($model->chapter_name) ?></h1> | ||
</div> | ||
<div class="view-content"><?= HtmlPurifier::process(Markdown::process($model->chapter_body)) ?></div> | ||
<?php $this->endContent() ?> |
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,25 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: yidashi | ||
* Date: 2016/12/15 | ||
* Time: 下午2:20 | ||
*/ | ||
/** | ||
* @var \yii\web\View $this | ||
* @var \common\models\BookChapter $model | ||
*/ | ||
|
||
use yii\helpers\Html; | ||
use yii\helpers\HtmlPurifier; | ||
use yii\helpers\Markdown; | ||
use backend\widgets\ActiveForm; | ||
|
||
$this->title = $model->chapter_name; | ||
$this->params['breadcrumbs'][] = ['label' => '书', 'url' => ['/book/index']]; | ||
$this->params['breadcrumbs'][] = ['label' => $model->book->book_name, 'url' => ['/book/view', 'id' => $model->book->id]]; | ||
$this->params['breadcrumbs'][] = Html::encode($model->chapter_name); | ||
?> | ||
<?php $this->beginContent('@backend/views/book/_layout.php', ['model' => $model]) ?> | ||
<?= $this->render('_form_chapter', ['model' => $model]) ?> | ||
<?php $this->endContent() ?> |
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,22 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: yidashi | ||
* Date: 2016/12/15 | ||
* Time: 下午2:20 | ||
*/ | ||
/** | ||
* @var \yii\web\View $this | ||
* @var \common\models\Book $model | ||
*/ | ||
|
||
use yii\helpers\Html; | ||
use yii\helpers\HtmlPurifier; | ||
use yii\helpers\Markdown; | ||
use backend\widgets\ActiveForm; | ||
|
||
$this->title = '新建书'; | ||
$this->params['breadcrumbs'][] = ['label' => '书', 'url' => ['/book/index']]; | ||
$this->params['breadcrumbs'][] = $this->title; | ||
?> | ||
<?= $this->render('_form', ['model' => $model]) ?> |
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,40 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: yidashi | ||
* Date: 2016/12/15 | ||
* Time: 下午6:46 | ||
*/ | ||
|
||
/** | ||
* @var \yii\web\View $this | ||
* @var \yii\data\ActiveDataProvider $dataProvider | ||
*/ | ||
|
||
$this->title = '书'; | ||
$this->params['breadcrumbs'][] = '书'; | ||
?> | ||
<p> | ||
<?= \yii\helpers\Html::a('新建书', 'create', ['class' => 'btn btn-primary btn-sm']) ?> | ||
</p> | ||
<div class="box box-solid"> | ||
<div class="box-body"> | ||
<?= \yii\grid\GridView::widget([ | ||
'dataProvider' => $dataProvider, | ||
'columns' => [ | ||
'id', | ||
[ | ||
'attribute' => 'book_name', | ||
'value' => function ($model) { | ||
return \yii\helpers\Html::a($model->book_name, ['update-chapter', 'id' => $model->id]); | ||
}, | ||
'format' => 'html' | ||
], | ||
'created_at:date', | ||
[ | ||
'class' => 'yii\grid\ActionColumn' | ||
] | ||
] | ||
]) ?> | ||
</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,25 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: yidashi | ||
* Date: 2016/12/15 | ||
* Time: 下午2:20 | ||
*/ | ||
/** | ||
* @var \yii\web\View $this | ||
* @var \common\models\BookChapter $model | ||
*/ | ||
|
||
use yii\helpers\Html; | ||
use yii\helpers\HtmlPurifier; | ||
use yii\helpers\Markdown; | ||
use backend\widgets\ActiveForm; | ||
|
||
$this->title = $model->chapter_name; | ||
$this->params['breadcrumbs'][] = ['label' => '书', 'url' => ['/book/index']]; | ||
$this->params['breadcrumbs'][] = ['label' => $model->book->book_name, 'url' => ['/book/view', 'id' => $model->book->id]]; | ||
$this->params['breadcrumbs'][] = Html::encode($model->chapter_name); | ||
?> | ||
<?php $this->beginContent('@backend/views/book/_layout.php', ['model' => $model]) ?> | ||
<?= $this->render('_form_chapter', ['model' => $model]) ?> | ||
<?php $this->endContent() ?> |
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,22 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: yidashi | ||
* Date: 2016/12/15 | ||
* Time: 下午2:20 | ||
*/ | ||
/** | ||
* @var \yii\web\View $this | ||
* @var \common\models\Book $model | ||
*/ | ||
|
||
use yii\helpers\Html; | ||
use yii\helpers\HtmlPurifier; | ||
use yii\helpers\Markdown; | ||
use backend\widgets\ActiveForm; | ||
|
||
$this->title = '编辑书:' . $model->book_name; | ||
$this->params['breadcrumbs'][] = ['label' => '书', 'url' => ['/book/index']]; | ||
$this->params['breadcrumbs'][] = $this->title; | ||
?> | ||
<?= $this->render('_form', ['model' => $model]) ?> |
Oops, something went wrong.