编辑add方法: ~~~ public function add() { $activeuser = UserModel::where('status',1)->find(); $this->assign('activeuser', $activeuser['username']); return $this->fetch(); } ~~~ 模板文件: /apps/index/view/template/add.html ~~~ {layout name="layout" /} <div class="container"> <div id="templateadd" class="formgrid"> <div class="sorting"> <div class="ui8-select"> <span class="active-option">当前账户:<em>{$activeuser}</em></span> </div> </div> <form method="post" autocomplete="off" name="moderate" id="moderate" action="http://127.0.0.1/tp5/public/index.php/index/template/"> <table class="formbox" cellpadding="1" cellspacing="0"> <tbody> <tr> <td><input type="text" id="tn" name="templatename" class="px" value="" tabindex="1" style="width: 170px" /> <span>模板名</span></td> <td><input type="text" id="tid" name="templateid" class="px" value="" tabindex="2" style="width: 170px" /> <span>模板ID</span></td> <td><input type="hidden" name="operation" value="addsubmit" /></td> </tr> </tbody> </table> <table class="formbox" cellpadding="1" cellspacing="0"> <tbody> <tr> <td><input type="text" id="tp" name="programmername" class="px" value="" tabindex="1" style="width: 170px" /> <span>程序</span></td> <td><input type="text" id="tpr" name="programmerrate" class="px" value="" tabindex="2" style="width: 170px" /> <span>分成示例 0.50</span></td> <td></td> </tr> </tbody> </table> <table class="formbox" cellpadding="1" cellspacing="0"> <tbody> <tr> <td><input type="text" id="td" name="designername" class="px" value="" tabindex="3" style="width: 170px" /> <span>美工</span></td> <td><input type="text" id="tdr" name="designerrate" class="px" value="" tabindex="4" style="width: 170px" /> <span>分成示例 0.50</span></td> <td></td> </tr> </tbody> </table> <table class="formbox" cellpadding="1" cellspacing="0"> <tbody> <tr> <td><input type="text" id="to1" name="other1name" class="px" value="" tabindex="5" style="width: 170px" /> <span>第三方一</span></td> <td><input type="text" id="to1r" name="other1rate" class="px" value="" tabindex="6" style="width: 170px" /> <span>分成示例 0.50</span></td> <td></td> </tr> </tbody> </table> <table class="formbox" cellpadding="1" cellspacing="0"> <tbody> <tr> <td><input type="text" id="to2" name="other2name" class="px" value="" tabindex="7" style="width: 170px" /> <span>第三方二</span></td> <td><input type="text" id="to2r" name="other2rate" class="px" value="" tabindex="8" style="width: 170px" /> <span>分成示例 0.50</span></td> <td></td> </tr> </tbody> </table> <table class="submitbox" cellpadding="1" cellspacing="0"> <tbody> <tr> <td><button type="submit" tabindex="100" class="pn pnc btn btn-small btn-green"><strong>提交</strong></button></td> </tr> </tbody> </table> </form> </div> </div> ~~~ 打开浏览器 http://127.0.0.1/tp5/public/index.php/index/template/add 页面输出类似![](https://box.kancloud.cn/2016-07-28_57997a6b3c04b.png) 编辑index方法: ~~~ if($this->request->method()=='POST') { $postdata = $this->request->only(['moderate','operation']); if($postdata['operation']=='addsubmit'){ // 录入模板 $post = $this->request->only(['templatename','templateid','programmername','programmerrate','designername','designerrate','other1name','other1rate','other2name','other2rate']); $tpl['uid'] = $activeuser['uid']; $tpl['tid'] = $post['templateid']; $tpl['tname'] = $post['templatename']; $tpl['pnick'] = $post['programmername']; $tpl['dnick'] = $post['designername']; $tpl['onick1'] = $post['other1name']; $tpl['onick2'] = $post['other2name']; $tpl['prate'] = $post['programmerrate']; $tpl['drate'] = $post['designerrate']; $tpl['orate1'] = $post['other1rate']; $tpl['orate2'] = $post['other2rate']; if($result = TplModel::create($tpl)){ //return '模板[ ' . $result->tname . ':' . $result->tid . ' ]新增成功'; //return $this->success('新增成功'); $this->redirect('http://127.0.0.1/tp5/public/index.php/index/template/'); }else{ return '新增出错'; } } ~~~