我是Yii2的新手。我有一个主页,有两个按钮' Create To Do'和'插入待办事项'。点击'创建待办事项后,会显示一个Div,其中包含两个文本字段和一个按钮' Insert To Do'点击插入,我想验证表格,然后在数据库中插入数据。下面是我的model.php文件
<?php
namespace app\models;
use Yii;
use yii\base\Model;
class InsertToDo extends Model
{
public $Date;
public $Description;
public function rules()
{
return [
[['Date','Description'],'required'],
['Date','date'],
];
}
}
以下是我的观看文件
<?php
/* @var $this yii\web\View */
$this->title = 'My First Project Home Page';
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use app\models\InsertToDo;
?>
<?php
$model = new InsertToDo;
$script = <<< JS
$(document).ready(function(){
$('#createToDo').hide();
$('#createToDoLink').click(function(){
$('#createToDo').fadeIn('slow');
});
});
JS;
$this->registerJs($script);
?>
<div class="site-index">
<div class="row">
<div class="col-lg-4">
<p><a class="btn btn-default" href="#" id="createToDoLink">Create To Do »</a></p>
</div>
</div>
<div id="createToDo">
<?php $form = yii\widgets\ActiveForm::begin(['id' => 'createToDo-form']);?>
<?php echo $form->field($model,'Date');?>
<?= $form->field($model,'Description');?>
<?= Html::submitButton('Create To Do',['class'=>'btn btn-success','id'=>'insertToDoButton']) ?>
<?php yii\widgets\ActiveForm::end();?>
</div>
请帮忙!