时间:2021-07-01 10:21:17 帮助过:10人阅读
public function food_add() { $Food=M('Food'); $FoodType=M("FoodType"); if (isset($_POST['save'])) { //判断是否已经添加了菜品 $viewpoint_id= $_GET['id']; $id=$_POST['names']; $this->food_add2($id,$viewpoint_id); } else { // 显示数据 $lists = $Food->field("food.name,food.food_type,food.price,food.id,manager.path") ->table($Food->getTableName()." food") ->join(M("file_manager")->getTableName()." manager on food.pic = manager.id") ->page($page)->order('food.id desc')->select(); foreach ($lists as $k => $v) { $lists[$k]['path'] = __ROOT__.$lists[$k]['path']; $lists[$k]['type_name'] = $FoodType->where("id={$v['food_type']}")->getField('type_name'); } $this->assign('lists', $lists); $this->display('food_add'); } }public function food_add2($id,$vid){ $Food=M('Food'); $FoodType=M("FoodType"); $FoodDinner=M('ViewpointDinner'); //获取FOODID $food_id= implode(',' ,$_POST['names']); $food_detail=$Food->where(array('id'=>array('in',$food_id)))->select(); $FoodDinner->create(); foreach ($food_detail as $k => $v) { $FoodDinner->id = $food_detail[$k]['id']; $FoodDinner->type = $food_detail[$k]['food_type']; $FoodDinner->names = $food_detail[$k]['name']; $FoodDinner->price = $food_detail[$k]['price']; $FoodDinner->pic = $food_detail[$k]['pic']; $FoodDinner->create_time = strtotime(date('Y-m-d H:i:s')); $FoodDinner->sort=1; //排序 $FoodDinner->is_low=1; //低消 $FoodDinner->viewpoint_id=$vid; $FoodDinner->add(); } }
//判断是否已经添加了菜品 $viewpoint_id= $_GET['id']; $id=$_POST['names'];
提交的方式是啥?
POST?
@namelesswei @shengli881026 感谢两位回复,提交是POST提交,$_GET['id']是获取从其他页面传过来的参数
传参链接如下:
添加低消
你的 $_POST['save'] 和 $_GET['id'] 分属于两个不同的来源
所以这两个值不可能同时存在
@xuzuning 请问如何处理呢?
表单有 action 属性,你的 id 可写在它上面
一个在表单里应隐藏控件传递,不过就不是 $_GET['id'] 而是 $_POST['id'] 了
@xuzuning 谢谢你的回复,已经解决了我的问题。也感谢@namelesswei @shengli881026的回复。