ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
![](https://img.kancloud.cn/3b/13/3b135bb95f69a881402b3de37dda3f75_709x546.png) > **分步表单构建器是依赖于表单构建器实现 ## 获取构建器实例 1. `ViewBuilder`中获取 ```php $viewBuilder = $this->viewBuilder; $formInstance = $viewBuilder->form_step; ``` 2. `instance()`自身方法 ```php $formBuilder= FormStepBuilder::instance(); ``` 3. `new`关键词 ```php $formBuilder= new FormStepBuilder([ 'id' => '__admin_form_step', ]); ``` ## 完整示例 ~~~ <?php /** * @link https://ym2.cleverstone.top * @copyright Copyright (c) 2020 Yii Manager Software LLC */ namespace backend\controllers; use builder\base\BaseController; use builder\form\FormBuilder; use builder\form_step\FormStepBuilder; use builder\form_step\util\fssr\Modal; use builder\form_step\util\step\Item; use builder\widget\ajax\Accordion; use builder\widget\ajax\ButtonDropdown; use builder\widget\ajax\Carousel; use builder\widget\WidgetFacade; /** * 分步表单 * @author cleverstone * @since ym2.0 */ class StepFormController extends BaseController { public $guestActions = [ 'index', ]; /** * @return string * @throws \Throwable */ public function actionIndex() { if ($this->isPost) { return $this->asOk('SUCCESS'); } else { $formStepBuilder = FormStepBuilder::instance(); $formStepBuilder->setTitle('分步表单') ->setStepItem(function (Item $item) { return $item->title('基本配置')->content(function (FormBuilder $formBuilder) { return $formBuilder->setRequiredStyle()->setFormControl([ 'a' => $this->formControl->text()->label('用户名')->required(), 'a1' => $this->formControl->text()->label('密码')->required(), 'a2' => $this->formControl->text()->label('SEO')->required(), 'a3' => $this->formControl->text()->label('分类')->required(), 'a4' => $this->formControl->text()->label('状态')->required(), ]); }); }) ->setStepItem(function (Item $item) { return $item->title('会员配置')->content(function (FormBuilder $formBuilder) { return $formBuilder->setRequiredStyle()->setFormControl([ 'b' => $this->formControl->text()->label('名称')->required(), 'b1' => $this->formControl->text()->label('性别')->required(), 'b2' => $this->formControl->text()->label('积分')->required(), 'b3' => $this->formControl->text()->label('代码')->required(), 'b4' => $this->formControl->text()->label('代理商')->required(), 'b5' => $this->formControl->text()->label('登录日期')->required(), ]); }); }) ->setStepItem(function (Item $item) { return $item->title('完成')->content(function (FormBuilder $formBuilder) { return $formBuilder->setRequiredStyle()->setFormControl([ 'c' => $this->formControl->text()->label('内容')->required(), 'c1' => $this->formControl->text()->label('理由')->required(), 'c2' => $this->formControl->text()->label('解决')->required(), 'c3' => $this->formControl->text()->label('爱好')->required(), ]); }); }) /*->setExtraBtn([ WidgetFacade::echo2Return(function () { \yii\bootstrap4\Modal::$autoIdPrefix = 'ModalB4'; \yii\bootstrap4\Modal::begin([ 'title' => 'ModalB4 title', 'bodyOptions' => [ 'class' => 'text-center', ], 'toggleButton' => [ 'label' => 'ModalB4 btn', 'class' => 'layui-btn layui-btn-sm layui-btn-primary', ], ]); echo implode("\n", array_fill(0, 100, 'ModalB4 content')); \yii\bootstrap4\Modal::end(); }), ])*/ /*->setExtraBtn([ WidgetFacade::echo2Return(function () { echo ButtonDropdown::widget([ 'label' => 'Action', 'dropdown' => [ 'items' => [ ['label' => 'DropdownA', 'url' => '/'], ['label' => 'DropdownB', 'url' => '#'], ], ], ]); }), ])*/ /*->setExtraBtn([ Accordion::widget([ 'options' => [ 'id' => 'wwwwww', ], 'items' => [ [ 'label' => 'Collapsible Group Item #1', 'content' => 'Anim pariatur cliche...', 'contentOptions' => ['class' => 'in'] ] ], ]), ])*/ /*->setExtraBtn([ WidgetFacade::echo2Return(function () { \builder\widget\ajax\Modal::begin([ 'id' => 'eeeeeeeeeeeeeeeeeeee', 'title' => 'ModalB4 title', 'bodyOptions' => [ 'class' => 'text-center', ], 'toggleButton' => [ 'label' => 'ModalB4 btn', 'class' => 'layui-btn layui-btn-sm layui-btn-primary', ], ]); echo implode("\n", array_fill(0, 100, 'ModalB4 content')); \builder\widget\ajax\Modal::end(); }), ])*/ ->setExtraBtn([ Carousel::widget([ 'id' => 'FFFFFFFFFFFFFFFFFFFFFFFFF', 'options' => [ 'ym2-image-group' => '', 'style' => 'width:100px;height:100px;', ], //'controls' => false, 'items' => [ [ 'content' => '<img ym2-full-image style="width:100px;height:100px;" src="https://buerzz.damanzj.com/upload/image/goods_manager/G20230720164108385/album_images/202306291606534csyPMlILJ.jpg"/>', ], [ 'content' => '<img ym2-full-image style="width:100px;height:100px;" src="https://buerzz.damanzj.com/upload/image/goods_manager/G20230720164108385/album_images/20230402153138IlzZxeOSV1.jpg"/>', ], [ 'content' => '<img ym2-full-image style="width:100px;height:100px;" src="https://buerzz.damanzj.com/upload/image/goods_comment/14219/6718/20230720145807HmPqj8T2R5.png"/>', ], ], ]), ]) ->setBackBtn() ->setSubmitConfirm() ->setFssRedirect(function (Modal $modal) { return $modal->title('测试'); }) ->setRootLayout([ 'class' => ['col-md-5'] ]) ->setSubmitBtn(); return $formStepBuilder->render(); } } } ~~~