Skip to content

Commit

Permalink
登录异步。简单的书
Browse files Browse the repository at this point in the history
  • Loading branch information
yidashi committed Dec 17, 2016
1 parent e51ef95 commit c611057
Show file tree
Hide file tree
Showing 44 changed files with 781 additions and 435 deletions.
2 changes: 0 additions & 2 deletions backend/config/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,12 @@
'generators' => [
'crud' => [
'class' => 'yii\gii\generators\crud\Generator',
'enableI18N' => true,
'templates' => [
'default' => '@gii/generators/crud/default'
]
],
'model' => [
'class' => 'gii\\generators\model\\Generator',
'enableI18N' => true,
'useTablePrefix' => true,
'ns' => 'common\\models'
]
Expand Down
96 changes: 96 additions & 0 deletions backend/controllers/BookController.php
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
]);
}
}
2 changes: 2 additions & 0 deletions backend/modules/gii/generators/model/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class Generator extends \yii\gii\generators\model\Generator
{
public $skipRuleColumns = ['created_at', 'updated_at'];

public $generateLabelsFromComments = true;

/**
* Generates validation rules for the specified table.
* @param \yii\db\TableSchema $table the table schema
Expand Down
1 change: 1 addition & 0 deletions backend/static/css/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ div.required label.control-label:after {
}
td{word-break: break-all}
.alert a {text-decoration: none!important;}
.editormd-fullscreen {z-index:99999!important;}
.sidebar-menu .treeview-menu {
display: none;
list-style: none;
Expand Down
29 changes: 29 additions & 0 deletions backend/views/book/_form.php
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>
23 changes: 23 additions & 0 deletions backend/views/book/_form_chapter.php
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() ?>
32 changes: 32 additions & 0 deletions backend/views/book/_layout.php
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>
27 changes: 27 additions & 0 deletions backend/views/book/chapter.php
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() ?>
25 changes: 25 additions & 0 deletions backend/views/book/create-chapter.php
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() ?>
22 changes: 22 additions & 0 deletions backend/views/book/create.php
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]) ?>
40 changes: 40 additions & 0 deletions backend/views/book/index.php
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>
25 changes: 25 additions & 0 deletions backend/views/book/update-chapter.php
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() ?>
22 changes: 22 additions & 0 deletions backend/views/book/update.php
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]) ?>
Loading

0 comments on commit c611057

Please sign in to comment.