我似乎无法在控制器中找到问题。这是我的代码。我确实使用print_r($ customer)检查了它,所有的信息都保存在我的表中,除了必须保存在文件中的文件名'柱。我无法找到错误。
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class billing extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
$this->load->model('Billing_model');
}
public function index()
{
$this->data['title'] = 'Billing';
$this->load->view('userheader');
$this->load->view('billing', $this->data);
//$this->load->view('billing', array('error' => ' ' ));
$this->load->view("userfooter");
}
public function do_upload()
{
$config['upload_path'] = './files/';
$config['allowed_types'] = 'gif|jpeg|jpg|png';
$config['max_size'] = '5000';
$config['overwrite'] = 'TRUE';
$this->load->library('upload', $config);
$this->load->initialize($config);
$design = 'design';
if ($this->upload->do_upload($design)) {
$file = $this->upload->data();
$customer = array(
'firstname' => $this->input->post('firstname'),
'lastname' => $this->input->post('lastname'),
'city' => $this->input->post('city'),
'address' => $this->input->post('address'),
'email' => $this->input->post('email'),
'contact' => $this->input->post('contact'),
'status' => 'Pending',
'file' => $file['file_name']
);
$cust_id = $this->Billing_model->insert_customer($customer);
$order = array(
'date' => date('Y-m-d'),
'customerid' => $cust_id
);
$ord_id = $this->Billing_model->insert_order($order);
if ($cart = $this->cart->contents()):
foreach ($cart as $item):
$order_detail = array(
'orderid' => $ord_id,
'productid' => $item['id'],
'quantity' => $item['qty'],
'price' => $item['price']
);
$cust_id = $this->Billing_model->insert_order_detail($order_detail);
endforeach;
endif;
$this->load->view('userheader');
//$this->load->view("success");
print_r($customer);
$this->load->view("userfooter");
} else {
$error = array('error' => $this->upload->display_errors());
$this->load->view('userheader');
$this->load->view('errormessage', $error);
$this->load->view('userfooter');
}
}
}
?>
答案 0 :(得分:1)
首先,类名必须是这样的......
class Billing extends CI_Controller {
您可以将控制器保存为“billing.php”,但班级名称的第一个字母必须是大写字母。
e.g:
login_ctrl.php -->>> class Login_ctrl extends CI_Controller {
user_names.php -->>> class User_Names extends CI_Controller {
试试吧。也许现在它可以运行.. :)