企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
1. 将更改根目录下在Shop/Controller文件夹下的AdminController.class.php为 ~~~ <?php namespace Shop\Controller; use Think\Controller; use Com\Wechat; use Com\WechatAuth; class AdminController extends Controller { public function add(){ $this->display(); } public function addgoods(){ header("Content-type:text/html;charset=utf-8"); $m=M('goods'); $upload = new \Think\Upload();// 实例化上传类 $upload->maxSize =3145728 ;// 设置附件上传大小 $upload->exts =array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型 $upload->rootPath ='./Public/Uploads/'; // 设置附件上传目录 // 上传文件 $info = $upload->upload(); if(!$info) {// 上传错误提示错误信息 echo '<script type="text/javascript">alert("上传图片失败");</script>'; exit; }else{// 上传成功 $_POST['img']=$info['img']['savepath'].$info['img']['savename']; $arr=$m->add($_POST); if($arr){ echo '<script type="text/javascript">alert("添加成功");history.go(-1);</script>'; }else{ echo '<script type="text/javascript">alert("添加失败");history.go(-1);</script>'; } } } //商品列表页 public function lists(){ $m=M('goods'); $data=$m->select(); $this->assign("data",$data); $this->display(); } //删除商品 public function del(){ header("Content-type:text/html;charset=utf-8"); $id=$_GET['id']; $m=M('goods'); $res=$m->delete($id); if($res){ echo '<script>alert("删除成功");history.go(-1);</script>'; }else{ echo '<script>alert("删除失败");history.go(-1);</script>'; } } } ~~~ 2. 将更改根目录下在Shop/View文件夹下的lists.html为 ~~~ <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! --> <title>益达微信商城开发课</title> <!-- Bootstrap --> <link href="__PUBLIC__/bootstrap/css/bootstrap.min.css" rel="stylesheet"> <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> <!--[if lt IE 9]> <script src="__PUBLIC__/bootstrap/js/html5shiv.min.js"></script> <script src="__PUBLIC__/bootstrap/js/respond.min.js"></script> <![endif]--> </head> <body> <nav class="navbar navbar-default"> <div class="container-fluid"> <div class="navbar-header"> <a class="navbar-brand" href="{:U('Admin/add')}"> <<商品添加 </a> </div> </div> </nav> <table class="table table-striped"> <tr> <th>序号</th> <th>商品名</th> <th>规格</th> <th>价格</th> <th>操作</th> </tr> <input type="hidden" value="{$i=0}" /> <foreach name="data" item="vo" > <tr> <td>{$i}</td> <td>{$vo.name}</td> <td>{$vo.pex}</td> <td>{$vo.pirce}</td> <td><a href="{:U('Admin/del',array('id'=>$vo['id']))}">删除</a></td> </tr> <input type="hidden" value="{$i++}"> </foreach> </table> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <script src="__PUBLIC__/bootstrap/js/jquery.min.js"></script> <!-- Include all compiled plugins (below), or include individual files as needed --> <script src="__PUBLIC__/bootstrap/js/bootstrap.min.js"></script> </body> </html> ~~~ 3. 在浏览器输入:域名//index.php/shop/admin/lists,并且商品添加与删除功能能实现 ![](https://box.kancloud.cn/b00e3bbb067ae86bce19465996795469_1440x323.png) 4. 本节相关源码下载(下载密码:idbk)点击[下载](https://pan.baidu.com/s/1HMx4GHjgR9nFYF5kgVQNRA)