ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## 导入构建器渲染输出 > 说明: 该方法用于导入构建器的渲染输出。 注意:需在控制器内,使用构建器实例对象调用`assign`方法实现。 > 示例: ```php <?php namespace app\demo\controller; use yunj\Controller; class FormDemo extends Controller { // 方式一 public function demo1(){ $builder=YI('demo2') ->sheets(["一年级","二年级","三年级","四年级"]) ->cols(function ($sheet){ $cols = [ 'name' => [ "title" => '姓名', "default" => "小王", "verify" => "require|chs", "desc" => "必填,只能输入汉字", ], 'sex' => [ "title" => '性别', 'default' => '男', 'verify' => 'require|in:男,女', "desc" => "必填,男/女", ], 'age' => [ "title" => '年龄', 'default' => '18', 'verify' => 'require|positiveInteger', "desc" => "必填,正整数", ] ]; return $cols; }) ->rows(function ($rows_data){ $datas = []; foreach ($rows_data as $id => $data) { $datas[] = [ "grade" => Grade::code($data["sheet"]), "sex" => Sex::code($data["row"]["sex"]), ] + $data["row"]; } $this->model->addRows($datas); return true; }); $builder->assign($this); return $this->fetch(); } // 方式二 public function demo2(){ $args = [ "sheets"=>["一年级","二年级","三年级","四年级"], "cols"=>function($sheet){ $cols = [ 'name' => [ "title" => '姓名', "default" => "小王", "verify" => "require|chs", "desc" => "必填,只能输入汉字", ], 'sex' => [ "title" => '性别', 'default' => '男', 'verify' => 'require|in:男,女', "desc" => "必填,男/女", ], 'age' => [ "title" => '年龄', 'default' => '18', 'verify' => 'require|positiveInteger', "desc" => "必填,正整数", ] ]; return $cols; }, "rows"=>function ($rows_data){ $datas = []; foreach ($rows_data as $id => $data) { $datas[] = [ "grade" => Grade::code($data["sheet"]), "sex" => Sex::code($data["row"]["sex"]), ] + $data["row"]; } $this->model->addRows($datas); return true; } ]; $builder=YF('demo2',$args); $builder->assign($this); return $this->fetch(); } } ```