访问尚未创建的变量

时间:2017-04-03 20:27:26

标签: php codeigniter variables

我在这里遇到一些麻烦V_shop_menu $ order_uuid没有填充。现在我猜这是因为它尚未创建,这将在下面进一步完成。我遇到的问题是这里有2个语句对表进行插入,但它们都相互依赖。

我有一些鸡肉和鸡蛋的情况,因为我需要从顶部区域的$ shop_menu_uuid来完成底部插入。我被引导相信,因为它们处于相同的公共功能中,它才会起作用,但事实并非如此。

我需要做些什么来实现这一目标?

谢谢!

public function add_shopmenu(){
    $postData = $this->input->post();

    $condition['conditions'][] = "site_name ='".$this->sessionInfo['site']."'";
    $site = $this->frontguide_Model->selectSingleRow("t_place",$condition);
    $site_uuid = $site['site_uuid'];

    unset($condition);
    $condition['conditions'][] = "site_uuid ='".$site['site_uuid']."'";
    $condition['conditions'][] = "shop_menu_name ='".$postData['shop_menu_name']."'";
    $shopmenu_name = $this->frontguide_Model->selectData("v_shop_menus",$condition);


     unset($condition);
    $condition['conditions'][] = "site_uuid ='".$site['site_uuid']."'";
    $shopmenus = $this->frontguide_Model->selectData("v_shop_menus",$condition);


    $shop_menu_enabled = (isset($postData['shop_menu_enabled']))?$postData['shop_menu_enabled']:"false";
    $shop_menu_uuid =  $this->frontguide_functions->uuid();
    $v_shop_menu= array(
        "shop_menu_uuid" =>$shop_menu_uuid,
        "site_uuid" =>$site_uuid,
        "order_uuid" =>$order_uuid,
        "shop_menu_extension" =>$shop_menu_extension,
        "shop_menu_name" =>$postData['shop_menu_name'],
        "shop_menu_greet_long" =>$postData['shop_menu_greet_long'],
        "shop_menu_greet_short" =>$postData['shop_menu_greet_short'],
        "shop_menu_timeout" =>$postData['shop_menu_timeout'],
        "shop_menu_enabled" => $shop_menu_enabled,
        "shop_menu_cid_prefix"=>$postData['shop_menu_cid_prefix']
    );
    log_message('debug',print_r($v_shop_menu,TRUE));

    $vgu_response = $this->frontguide_Model->insert("v_shop_menus",$v_shop_menu);

    $shop_menu_option_digits = $postData['shop_menu_option_digits'];
    $shop_menu_option_order = $postData['shop_menu_option_order'];
    $shop_menu_option_description = $postData['shop_menu_option_description'];
    $shop_menu_option_param = $postData['shop_menu_option_param'];

    for($i=0;$i<count($shop_menu_option_digits);$i++){
        $option = array();
        $option['shop_menu_option_digits'] = $shop_menu_option_digits[$i];
        $option['shop_menu_option_order'] = $shop_menu_option_order[$i];
        $option['shop_menu_option_description'] = $shop_menu_option_description[$i];
        $option['shop_menu_option_param'] = $shop_menu_option_param[$i];
        $shop_menu_option_uuid=  $this->frontguide_functions->uuid();
        $option['shop_menu_option_uuid'] = $shop_menu_option_uuid;
        $option['shop_menu_uuid'] = $shop_menu_uuid;
        $option['site_uuid'] = $site_uuid;
        $vgu_response = $this->frontguide_Model->insert("v_shop_menu_options",$option);
    }


   $order_uuid =  $this->frontguide_functions->uuid();
   $order_data = array(
        "site_uuid"=>$site_uuid,
        "order_uuid"=>$order_uuid,
        “offer_uuid" => "a6788e9b-67bc-bd1b-df59-ggg5d51289ab",
        "order_context"=>$site['site_name'],
        "order_name" =>$postData['shop_menu_name'],
        "order_number" =>$shop_menu_extension,
        "order_continue" =>'true',
        "order_order" =>'333',
        "order_enabled" =>"true",
    );

    $v_orders = $this->frontguide_Model->insert("v_orders",$order_data);

1 个答案:

答案 0 :(得分:0)

  

现在我猜测这是因为它尚未创建,这已经完成了   在下面。

是的,你是对的。

这很简单。 不使用v_shop_menus插入$order_uuid数据。 插入v_orders后,获取$order_uuid并使用v_shop_menus更新$shop_menu_uuid