2013-08-01 54 views
0

在我的控制器中,我有一行需要将$ content ['pass_check']传递给视图。它位于if语句中,用于检查验证。我发现这导致它破裂。一旦我在任何if语句之外移动$ content ['pass_check'],它就可以很好地传递给视图。所有其他值均被传递(帐户,费用帐户,供应商,条款)。我必须做些什么才能让它通过这个if语句。我甚至尝试将它移到验证之外,但它仍然不会设置。无法传递codeigniter控制器中的数组值以查看

function create() { 
    require_permission("INVOICE_EDIT"); 

    $this->load->library("form_validation"); 
    $this->form_validation->set_rules("invoice_number", "Invoice Number", "required"); 

    if($this->form_validation->run() !== false) { 
     $post = $this->input->post(); 

     $this->session->set_userdata("create_invoice_vendor", $post['vendor_id']); 
     $this->session->set_userdata("create_invoice_date", $post['invoice_date']); 

     $invoice_number_exists = $this->invoices->count(array("invoice_number" => $post['invoice_number'])) > 0; 

     $post['invoice_date'] = date("Y-m-d", strtotime($post['invoice_date'])); 
     $post['due_date'] = date("Y-m-d", strtotime($post['due_date'])); 
     $post['date_entered'] = "now()"; 

     $id = $this->invoices->insert_invoice($post); 

     $this->load->model("vendors"); 

     if(isset($post['invoice_number'])){ 
      $string_check= $post['invoice_number']; 
      $string_check= preg_replace('/\d/', '#', $string_check); 
      $string_check= preg_replace('/\w/', '#', $string_check); 

      $invoice_pattern=array(); 
      $invoice_pattern = $this->db->select("invoice_pattern")->where("vendor_id", 
             $post['vendor_id'])->get("vendors")->result(); 
      $invoice_pattern=$invoice_pattern[0]->invoice_pattern; 

* ////这是我需要帮助///////

    if($invoice_pattern == $string_check){ 
         ***$content['post_check'] = 1;*** 
         $this->invoices->flag_invoice($id); 
        }; 

       }; 



       $history = array(
        "type"  => "invoice_entered", 
        "comments" => "Invoice was entered", 
        "link"  => $id, 
        "admin_id" => $this->user->admin_id, 
        "date"  => "now()", 
        ); 
       $this->vendors->insert_history($post['vendor_id'], $history); 

       if($post['flagged'] == 1) { 
        $this->invoices->flag_invoice($id); 
       } 

       if($invoice_number_exists) { 
        redirect("invoices/confirm_invoice/".$id); 
       } else { 
        // redirect("invoices/view/".$id); 
        redirect("invoices/create"); 
       } 
     } 

      $content['accounts'] = $this->db->get("acct_chart_of_accounts")->result(); 
      $content['expense_accounts'] = $this->db->get("invoice_expense_accounts")->result(); 
      $content['vendors'] = $this->db->select("vendor_id, name, terms, override, invoice_pattern") 
          ->order_by("name ASC")->get("vendors")->result(); 
      $content['terms'] = $this->db->query("SELECT DISTINCT(terms) FROM vendors")->result(); 
     } 
    } 

    $this->template['sub_heading'] = "Create"; 
    $this->template['content'] = $this->load->view("invoices/create", $content, true); 
    $this->template['sidebar'] = $this->load->view("invoices/sidebar", array(), true); 
    $this->template['scripts'] = array("codeigniter/javascript/invoices/create.js"); 
    $this->template['styles'][] = "codeigniter/styles/invoices/create.css"; 

    $this->display(); 
} 
+0

BREAK是什么意思? – RiggsFolly

回答

0

显然也不会,如果条件不传递给视图匹配,因为如果它匹配,你只是在条件内声明变量。

只需在条件检查之前创建$ content ['pass_check'],初始值为0或任何其他内容。

function create() { 

    ...snip... 

    $content['pass_check'] = 0; 

    if($invoice_pattern == $string_check) { 
     $content['post_check'] = 1; 
     $this->invoices->flag_invoice($id); 
    }; 

    ...snip... 
} 

让我知道,如果这工作或不请。

相关问题