在 Yii2 中使用文本字段添加记录

Use text field to add a record in Yii2

如何在 yii2 中通过文本字段添加记录?

请解释我必须在控制器、视图和模型中做什么以及我需要的任何东西

public function actionAdd() {
  ????
}

你必须有像这样的动作名称的表单

控制器:

public function actionCreate()
{
  $model = new News();
  if($model->load(Yii::$app->request->post())){
     if($model->save())
         return $this->redirect(['view', 'id' => $model->id ]);
     }
} 

在视图文件夹中:

create.php:

<?php $form = ActiveForm::begin() ?>

    <?= $form->field($model, 'text') ?>

    <?= Html::submitButton('submit') ?>

 <?php ActiveForm::end() ?>