访问尚未创建的变量

I'm having some trouble here V_shop_menu $order_uuid is not populating. Now I'm guessing this is because its yet to be created this is done further below. The problem I have is there are 2 statements here doing inserts to tables but they both rely on each other.

I have a bit of chicken and egg situation as I need $shop_menu_uuid from the top area to complete the bottom insert. I was led to believe that as they are in the same public function it would just work but this is not the case.

What do I need to do to make this happen?

Thanks!

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);

Now I'm guessing this is because its yet to be created this is done further below.

Yes you are right.

It is quite simple. Insert v_shop_menus data without $order_uuid . after inserting in v_orders, get the $order_uuid and update the v_shop_menus using $shop_menu_uuid.