ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
~~~ /** * 新增 * @author 似水星辰 [2630481389@qq.com] * @return mixed */ public function add() { // 保存数据 if ($this->request->isPost()) { // 表单数据 $data = $this->request->post(); // 验证 $result = $this->validate($data, 'Address'); if (true !== $result) $this->error($result); if ($page = AddressModel::create($data)) { $this->success('新增成功', cookie('__forward__')); } else { $this->error('新增失败'); } } $fields = [ ['type' => 'text', 'name' => 'user_name', 'title' => '姓名', 'tips' => '', 'attr' => '', 'value' => ''], ['type' => 'text', 'name' => 'user_phone', 'title' => '收货电话', 'tips' => '', 'attr' => '', 'value' => ''], ['type' => 'text', 'name' => 'user_address', 'title' => '收货人地址', 'tips' => '', 'attr' => '', 'value' => ''], ['type' => 'radio', 'name' => 'is_default', 'title' => '是否默认', 'tips' => '', 'attr' => '', 'value' => '1'], ['type' => 'text', 'name' => 'uid', 'title' => '会员昵称', 'tips' => '', 'attr' => '', 'value' => '0'], ]; $this->assign('page_title', '新增会员地址'); $this->assign('form_items', $fields); return $this->fetch('admin@public/add'); } ~~~ 如果创建的是admin模块的表单,则最后的渲染语句是 ~~~ return $this->fetch('public/add'); ~~~ $fields是手动构建出来的,也可以使用自动的,但是自动的扩展性不强,参照一下代码 ~~~ $fields = FieldModel::where('model',1)->order('sort asc,id asc')->column(true); foreach ($fields as &$value) { // 解析options if ($value['extra'] != '') { $value['extra'] = parse_attr($value['extra']); } switch ($value['type']) { case 'linkage':// 解析联动下拉框异步请求地址 if (!empty($value['ajax_url']) && substr($value['ajax_url'], 0, 4) != 'http') { $value['ajax_url'] = url($value['ajax_url']); } break; case 'date': case 'time': case 'datetime': $value['value'] = ''; break; } } ~~~