企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# Niushop开源商城后台表单 --- **niushop后台表单原理** 1. 添加信息表单 2. niushop后台配置添加修改数据与页面用一个控制器方法,方便管理权限 3. 控制器一般不能调用model直接操作数据,而是调用data/service下面对应的服务层方法 4. 返回数据用ajaxReturn函数对数据处理 5. 加载页面用$this->style样式 ```php /** * 添加文章 */ public function addArticle() { $article = new Article(); //niushop后台配置添加修改数据与页面用一个控制器方法,方便管理权限 if (request()->isAjax()) { $title = request()->post('title', ''); $class_id = request()->post('class_id', ''); $short_title = request()->post('short_title', ''); $source = request()->post('source', ''); $url = request()->post('url', ''); $author = request()->post('author', ''); $summary = request()->post('summary', ''); $content = request()->post('content', ''); $image = request()->post('image', ''); $keyword = request()->post('keyword', ''); $article_id_array = request()->post('article_id_array', ''); $click = request()->post('click', ''); $sort = request()->post('sort', ''); $commend_flag = request()->post('commend_flag', ''); $comment_flag = request()->post('comment_flag', ''); $attachment_path = request()->post('attachment_path', ''); $tag = request()->post('tag', ''); $comment_count = request()->post('comment_count', ''); $share_count = request()->post('share_count', ''); $status = 2; $data = array( 'title' => $title, 'class_id' => $class_id, 'short_title' => $short_title, 'source' => $source, 'url' => $url, 'author' => $author, 'summary' => $summary, 'content' => $content, 'image' => $image, 'keyword' => $keyword, 'article_id_array' => $article_id_array, 'click' => $click, 'sort' => $sort, 'commend_flag' => $commend_flag, 'comment_flag' => $comment_flag, 'status' => $status, 'attachment_path' => $attachment_path, 'tag' => $tag, 'comment_count' => $comment_count, 'share_count' => $share_count, 'uid' => $this->uid, 'public_time' => time(), 'create_time' => time() ); //控制器一般不能调用model直接操作数据,而是调用data/service下面对应的服务层方法 $result = $article->addArticle($data); //返回数据用ajaxReturn函数对数据处理 return AjaxReturn($result); } else { $articleClassList = $article->getArticleClass(); $this->assign('articleClassList', $articleClassList); return view($this->style . 'Cms/addArticle'); } } ``` ```js var flag = false;//防止重复提交 function save(type){ if(!validation()){ return; } var comment_flag = $("#comment_flag").prop('checked') ? 1 : 0 ; var commend_flag = $("#commend_flag").prop('checked') ? 1 : 0 ; var title=$("#title").val(); var class_id=$("#class_id").val(); var short_title=$("#short_title").val(); var source=$("#source").val(); var url=$("#url").val(); var author=$("#author").val(); var summary=$("#summary").val(); var content = UE.getEditor('editor').getContent(); if(content.length>65535){ showTip("文章内容太长","warning"); return; } var image=$("#title_img").val(); var keyword=$("#keyword").val(); var article_id_array=$("#article_id_array").val(); var click=$("#click").val(); var sort=$("#sort").val(); var tag=$("#tag").val(); var comment_count=$("#comment_count").val(); var share_count=$("#share_count").val(); var attachment_path = $("#attachment").val(); if(flag) return; flag = true; $.ajax({ type:"post", url:"{:__URL('ADMIN_MAIN/Cms/addArticle')}", data:{ 'title':title, 'class_id':class_id, 'short_title':short_title, 'source':source, 'url':url, 'author':author, 'summary':summary, 'content':content, 'image':image, 'keyword':keyword, 'article_id_array':article_id_array, 'click':click, 'sort':sort, 'commend_flag':commend_flag, 'comment_flag':comment_flag, 'attachment_path':attachment_path, 'tag':tag, 'comment_count':comment_count, 'share_count':share_count }, success:function(data){ if (data["code"] > 0) { showTip(data["message"],'success'); if(type==1){ location.href=__URL("ADMIN_MAIN/cms/articlelist"); } if(type==2){ window.open(__URL("SHOP_MAIN/article/detail?article_id="+data['code'])); } }else{ showTip(data["message"],'error'); flag = false; } } }); } ```