1.文章创建
创建基础控制器与表单
创建控制器中的文章操作
1. 首先要使用命名空间下的表单模型
2. 创建操作
3. 实例化表单模型
4. 渲染页面并且携带model
代码:use frontend\models\PostForm;
return $this->render('create',['model'=>$model]);
创建基础表单
1. 做面包屑 对于数据的封装(导航条)
2. 使用 use yii\bootstrap\ActiveForm; #引入js框架调节样式
use yii\helpers\Html; #使用html标签页面
3. form表单的格式写法
<?php $form = ActiveForm::begin() ?>
<?= $form->field($model,'title')->textinput(['maxlength'=>true]) ?>
<?= $form->field($model,'cat_id')->dropDownList(['1'=>'分类1','2'=>'分类2']) ?>
<div class="form-group">
<?=Html::submitButton('发布',['class'=>'btn btn-success'])?>
</div>
<?php ActiveForm::end() ?>
==========================================================================
整体代码:
<?php
$this->title = '创建';
$this->params['breadcrumbs'][] = ['label' =>'文章','url'=>['post/index']]; #面包屑 对于数据的封装
$this->params['breadcrumbs'][] = $this->title;
// use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\helpers\Html;
// use frontend\assets\AppAsset;
// AppAsset::register($this);
?>
<div class="row">
<div class="col-lg-9">
<div class="panel-title box-title">
<span>创建文章</span>
</div>
<div class="panel-body">
<?php $form = ActiveForm::begin() ?>
<?= $form->field($model,'title')->textinput(['maxlength'=>true]) ?>
<?= $form->field($model,'cat_id')->dropDownList(['1'=>'分类1','2'=>'分类2']) ?>
<?= $form->field($model,'label_img')->textinput(['maxlength'=>true]) ?>
<?= $form->field($model,'content')->textinput(['maxlength'=>true]) ?>
<?= $form->field($model,'tags')->textinput(['maxlength'=>true]) ?>
<div class="form-group">
<?=Html::submitButton('发布',['class'=>'btn btn-success'])?>
</div>
<?php ActiveForm::end() ?>
</div>
</div>
<div class="col-lg-3">
<div class="panel-title box-title">
<span>注意事项</span>
</div>
<div class="panel-body">
<p>1.2313213</p>
<p>2.3213213</p>
</div>
</div>
</div>
表单代码图片
需要记忆的是bootstrap的样式class类
<div class="col-lg-9">
<div class="panel-title box-title">
<div class="panel-body">
<div class="col-lg-3">
<div class="panel-title box-title">
<div class="panel-body">