Codeigniter提交表单不起作用,空白页

时间:2015-09-17 11:04:33

标签: codeigniter

我正在尝试提交带有codeigniter的表单,当我提交表单时,请获取一个空白页面。我哪里出错?

查看

echo "<form class='order_ctn_parent' method='POST' action='add/insert_orders'>";
//inputs
echo "</form>";

控制器

class Add extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
    }

    public function index() {

    }


       public function insert_orders()
    {
        $this->load->model('order_model', 'order');

        $this->order->insert_orders();
        redirect('view_orders', 'location');
    }

}

模型

class Order_model extends CI_Model {    
public function insert_orders()
        {
        $DB2 = $this->load->database('orders', TRUE);

                $timber_array = $this->input->post("timber_choose");
                $products_array = $this->input->post("product_choose");
                $qty_array = $this->input->post("quantity");
                $price_array = $this->input->post("price");
                $qty_array = $this->input->post("quantity");


                $loop = 0;
                foreach($products_array as $product) {

                    $price = str_replace("£","",$price_array[$loop]);

                    $data = array(
                       'product_code' => "",
                       'timber_type' => $timber_array[$loop],
                       'product' => $product,
                       'quantity' => $qty_array[$loop],
                       'price' =>  $price
                    );

                    $DB2->insert('timber_order_products', $data); 

                    $loop++;
                }
        }
}

2 个答案:

答案 0 :(得分:1)

尝试这样的事情

?>//end of php

<form class='order_ctn_parent' method='POST' action='<?php echo base_url()?>add/insert_orders'>

</form>

并在__construct()中加载模型,就像这样

public function __construct()
{
    parent::__construct();
    $this->load->model('order_model', 'order');
}

,无需检查$DB2 = $this->load->database('orders', TRUE);

和Codeigniter插入应为Like This

答案 1 :(得分:0)

提交后请检查您的网址。我相信你的表格行动不起作用。将适当的控制器及其功能url提供给Form动作。例子就在这里。

<?php echo site_url('add/insert_orders);?>

其中add将是您的控制器,insert_orders将是添加控制器的功能。