YII框架简介:
MVC
哲学:简单且优雅
全栈框架:提供:query buliders, ActiveRecord; RESTful API, multi-tier caching
可扩展
高性能
object-oriented programming (OOP)
用表单:
创建model:
class EntryForm extends Model
{
public $name;
public function rules()
{
return [
[['name'],'required'],
]
}
}
创建Action:
class SiteController extends Controller
{
public function actionEntry()
{
$model = new EntryForm();
if($model->load(Yii::$app->request->post()) && $model->validate()){
return $this->render('entry-confirm', ['model' => $model]);
}else{
return $this->render('entry',['model' => $model]);
}
}
}
创建视图:
entry-confirm:
<label>Name</label>: <?= Html::encode($model->name) ?>
entry:
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'name') ?>
<div class="form-group">
<?= Html::submitButton('Submit', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>