【发布时间】:2014-11-07 17:55:02
【问题描述】:
我是从 Yii 框架开始的,它是我的第一个框架……直言不讳:
我有一个 CMS 的表单来输入新的博客文章、文章。我还创建了一个调试视图,以便在将数据保存到数据库之前查看正在传递的数据,问题是当我使用字段的表单 2 时,不会将任何数据传递给调试视图......我希望更有经验的人可能有助于了解我在这里做错了什么。
我的代码:
-表单视图(new.php)
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'Title') ?>
<?= $form->field($model, 'PublicationDate')->input('date') ?>
<?= $form->field($model, 'Content')->textarea(['rows' => 5]) ?>
<?= $form->field($model, 'tags') ?>
<div class="form-group">
<?= Html::submitInput('Submint', ['class' => 'btn-primary']) ?>
</div>
文章模型(Article.php):
<?php
namespace app\models;
use yii\db\ActiveRecord;
class Article extends ActiveRecord{
public $tags;
public static function tableName()
{
return 'Article';
}
public function rules()
{
return[
[['Title', 'Content'], 'required'],
];
}
}
调试视图:
<?php
use yii\helpers\Html;
?>
<p>You have entered the following information:</p>
<ul>
<li><label>Title</label>: <?= Html::encode($model->Title) ?></li>
<li><label>PublicationDate</label>: <?= Html::encode($model->PublicationDate) ?></li>
<li><label>Content</label>: <?= Html::encode($model->Content) ?></li>
<li><label>tags</label>: <?= Html::encode($model->tags) ?></li>
</ul>
提前感谢您的时间:)
【问题讨论】:
标签: php activerecord yii2