public function add() { if (IS_POST) { $model = new \Model\GoodsModel(); if ($data = $model->create()) { if ($model->add($data)) { $this->success('添加成功', U('showlist'), 1); exit; } else { $error = $model->getError(); //获取模型里面的error属性的值 if (empty($error)) { $error = '添加失败'; } $this->error($error); } } else { $this->error($model->getError()); } } //取出商品栏目 $cat_model = new \Model\CategoryModel(); $cat_list = $cat_model->getTree(); $this->assign('cat_list', $cat_list); //取出商品类别 $type_list = M('type')->select(); $this->assign('type_list', $type_list); $this->display(); }
public function update($goods_id) { $goods = new \Model\GoodsModel(); if (!empty($_POST)) { if ($_FILES['goods_img']['error'] === 0) { $cfg = array('rootPath' => './Admin/Public/goods/'); $up = new \Think\Upload($cfg); $z = $up->uploadOne($_FILES['goods_img']); $_POST['goods_big_img'] = $up->rootPath . $z['savepath'] . $z['savename']; $bigimg = $_POST['goods_big_img']; //对上传图片进行缩略图处理 $im = new \Think\Image(); //实例化对象 $im->open($bigimg); //相对服务器路径打开图片 $im->thumb(165, 165, 3); //自适应大小制作缩略图 $smallimg = $up->rootPath . $z['savepath'] . "small_" . $z['savename']; $im->save($smallimg); //保存 $_POST['goods_small_img'] = $smallimg; //var_dump($_POST['goods_big_img']);die; } $arr = $goods->create(); $result = $goods->save($arr); if ($result) { $this->redirect('showlist', array(), 2, '修改商品成功'); } else { var_dump($goods->getError()); } } $category = new \Model\CategoryModel(); $cats = $category->select(); $this->assign('cats', $cats); $info = $goods->find($goods_id); $this->assign('info', $info); $this->display(); }