如何创建yii2html表单和操作

如何创建yii2html表单和操作,yii2,Yii2,我想创建一个带有控制器操作的基本Yi2HTML,如下所示 <?= \yii\helpers\Html::beginForm('index.php?r=userprofile/changeusername','post') ?> <div class="form-group"> <label for="inputsm">Ch

我想创建一个带有控制器操作的基本Yi2HTML,如下所示

<?= \yii\helpers\Html::beginForm('index.php?r=userprofile/changeusername','post') ?>
                                  <div class="form-group">
                                    <label for="inputsm">Change Username</label>
                                    <?= Html::textInput('username'); ?>
                                    <button type="submit" name="submit" class="btn btn-sm btn-theme">Change</button>
                                    <?= Html::button('Press me!', ['class' => 'submit']) ?>
                                  </div>
                                  <?= \yii\helpers\Html::endForm() ?>


更改用户名
改变

如何对此进行控制器操作最好转到
WEB
文件并配置Gii工具。(或检查)。GII指南:这个或在这个上面。
use Yii;

class UserprofileController extends yii\web\Controller
{
  # code...

  public function actionChangeusername()
  {
    # code...

    if (Yii::$app->request->post()) {
        # code...
        return $this->redirect('path/...');  // sample ...
     }

     return $this->render('index', [
         'param' => $var,  /* sample: Access to variables in the view ... */
     ]);
  }
//...

}

然后转到本地主机。或example.com/gii
如果您已经启用了漂亮的URL,请参阅本教程
您可以轻松创建模型、表单、控制器,甚至CRUD和。。在yii2中使用Gii

Yii包括一个名为Gii的便捷工具,它通过生成常用代码片段以及完整的CRUD控制器来提供快速原型。 Gii为您提供了一个基于Web的界面,以交互方式生成所需的代码。它还为大多数时候喜欢使用控制台窗口的人提供了一个命令行界面

视图的控制器:
use Yii;

class UserprofileController extends yii\web\Controller
{
  # code...

  public function actionChangeusername()
  {
    # code...

    if (Yii::$app->request->post()) {
        # code...
        return $this->redirect('path/...');  // sample ...
     }

     return $this->render('index', [
         'param' => $var,  /* sample: Access to variables in the view ... */
     ]);
  }
//...

}
如果要验证表单(通过模型…),应使用
activeTextInput

还可以阅读以下类和小部件:
, ,
(,…)