Thursday 15 April 2010

php - Why does my activerecord form lose the data? Yii2 framework -



php - Why does my activerecord form lose the data? Yii2 framework -

i starting yii framework, , first framework... point:

i have form cms come in new blog post, article. created debug view see info beingness passed before save in database, thing when utilize form 2 of fields dont pass info debug view... hope more experienced people might help see doing wrong here.

my code:

-form view(new.php)

<?php utilize yii\helpers\html; utilize 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 model(article.php):

<?php namespace app\models; utilize yii\db\activerecord; class article extends activerecord{ public $tags; public static function tablename() { homecoming 'article'; } public function rules() { return[ [['title', 'content'], 'required'], ]; } }

debug view:

<?php utilize yii\helpers\html; ?> <p>you have entered next 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>

thank in advance time :)

only safe attributes can receive user input. attribute considered safe when there @ to the lowest degree 1 validator defined attribute in rules(). if want declare attribute safe without doing farther validation, can utilize "safe" validator, this:

public function rules() { return[ [['title', 'content'], 'required'], [['publicationdate', 'tags'], 'safe'], ]; }

check http://www.yiiframework.com/doc-2.0/guide-input-validation.html , http://www.yiiframework.com/doc-2.0/guide-tutorial-core-validators.html more info.

php activerecord yii2

No comments:

Post a Comment