ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 当前平台已停止维护,请尽快迁移至[云静Admin TP6](https://gitee.com/worklz/yunj-admin-tp6) [https://gitee.com/worklz/yunj-admin-tp6](https://gitee.com/worklz/yunj-admin-tp6) ***** ## 导入构建器渲染输出 * **方法一:页面内只有单一导入时** > 注意!此方法仅支持渲染一个导入构建器,不需要写视图文件 控制器代码示例如下: ```php namespace app\demo\controller; use yunj\Controller; class FormDemo extends Controller { public function demo(){ $builder=YI('demo') ->sheets("一年级","二年级","三年级","四年级") ->cols([ 'name' => [ "title" => '姓名', "default" => "小王", "verify" => "require|chs", "desc" => "必填,只能输入汉字", ], 'sex' => [ "title" => '性别', 'default' => '男', 'verify' => 'require|in:男,女', "desc" => "必填,男/女", ], 'age' => [ "title" => '年龄', 'default' => '18', 'verify' => 'require|positiveInteger', "desc" => "必填,正整数", ] ]) ->rows(function ($rowsData){ $datas = []; foreach ($rowsData as $id => $data) { $datas[] = [ "grade" => Grade::getValueByTitle($data["sheet"]), "sex" => Sex::getValueByTitle($data["row"]["sex"]), ] + $data["row"]; } $this->model->addRows($datas); return true; }); return view_import($builder); } } ``` 不需要视图文件! * **方法二:自定义页面内容时** > 注意!此方法支持一个页面渲染多个导入构建器,需要写视图文件 控制器代码示例如下: ```php namespace app\demo\controller; use yunj\Controller; class FormDemo extends Controller { public function demo(){ // 导入构建器配置参考方法一 $builder=YI('demo'); // 多个构建器可反复调用此方法 $builder->assign($this); $builder->assign($this); return $this->fetch(); } } ``` 视图代码示例如下: ```html <!-- 继承公共模板文件 --> {extend name="$adminPage"} <!-- 重写content内容 --> {block name="content"} <!-- import标签定义type属性为yunj,id与后端数据导入构建器id一致 --> <import type="yunj" id="demo"></import> {/block} ```