这是我的控制者:
class Customer_update extends CI_Controller{
//construct
public function __construct(){
//consrtuct
parent::__construct();
$this->load->model('Customer_model_update');
$this->output->enable_profiler(TRUE);
}
//all customer fetch
public function edit(){
$customer_id = $this->uri->segment(3);
$data['customer_list'] = $this->Customer_model_update->showCustomer($customer_id);
$this->loadView('customer/upd',$data);
}
//update customer table
public function Update(){
$data = array(
'customer_id'=>$this->input->post('customer_id'),
'customer_name' => $this->input->post('customer_name'),
'customer_location' => $this->input->post('customer_location'),
'customer_phone1' => $this->input->post('customer_phone1'),
'customer_phone2' => $this->input->post('customer_phone2'),
'customer_phone3' => $this->input->post('customer_phone3'),
'customer_phone4' => $this->input->post('customer_phone4'),
'customer_phone5' => $this->input->post('customer_phone5'),
'customer_type' => $this->input->post('customer_type'),
'customer_status' => $this->input->post('1'),
'updated_date' => date("Y-m-d H:i:s")
);
$query = $this->Customer_model_update->customer_Update($data);
if($data !== NULL){
//add address table
$this->addressUpdate($data);
//add car table
$this->carUpdate($data);
}
var_dump($query);
//redirect('customer_list',$query);
}
//update address table
public function addressUpdate(){
$data = array(
'customer_id'=>$this->input->post('customer_id'),
'address_houseno' => $this->input->post('address_houseno'),
'address_street' => $this->input->post('address_street'),
'address_city' => $this->input->post('address_city'),
'address_landmark' => $this->input->post('address_landmark'),
'address_status' => $this->input->post('1'),
'updated_date' => date("Y-m-d H:i:s")
);
$this->Customer_model_update->address_Update($data);
}
//update car table
function carUpdate(){
$data = array(
'customer_id'=>$this->input->post('customer_id'),
'car_type' => $this->input->post('car_type'),
'car_model' => $this->input->post('car_model'),
'car_status' => $this->input->post('1'),
'updated_date' => date("Y-m-d H:i:s")
);
$this->Customer_model_update->car_Update($data);
}
//load view
public function loadView($view, $data=array()){
$this->load->view('common/header', $data);
$this->load->view($view, $data);
$this->load->view('common/footer', $data);
}
}
这是我的模特
class Customer_model_update extends CI_Model{
public function __construct(){
// constructor
parent::__construct();
}
//show all tables
public function showCustomer($customer_id){
$this->db->select('*');
$this->db->from('du_customer');
$this->db->join('du_customer_address','du_customer.customer_id = du_customer_address.customer_id');
$this->db->join('du_customer_car', 'du_customer_address.customer_id = du_customer_car.customer_id');
$this->db->where('du_customer.customer_id', $customer_id);
$query = $this->db->get();
return $query->result();
if(!$query=1){
return true;
}
}
public function customer_Update($data){
// update data array into du_customer
$customer_id = $this->input->post('customer_id');
$this->db->where('customer_id',$customer_id);
$this->db->update('du_customer',$data);
}
public function address_Update($data){
// update data array into du_customer_address table
$customer_id = $this->input->post('customer_id');
$this->db->where('customer_id',$customer_id);
$this->db->update('du_customer_address',$data);
}
public function car_Update($data){
// update data array into du_customer_car_table
$customer_id = $this->input->post('customer_id');
$this->db->where('customer_id', $customer_id);
$this->db->update('du_customer_car',$data);
}
}
我不知道这段代码有什么问题。 更新后,值发布为空。这是问题。
答案 0 :(得分:1)
是的,我通过使用array解决了这个问题, 我的控制器是
load-> model('Customer_model_update'); $ this-> output-> enable_profiler(TRUE); } 公共功能编辑($ customer_id){ $ customer = array(); $ addresses = array(); $汽车= array(); //获取客户详细信息 $ customer = $ this-> Customer_model_update-> getCustomer($ customer_id); // TODO:获取地址详细信息 $ addresses = $ this-> Customer_model_update-> getCustomerAddresses($ customer_id); //获取汽车详细信息 $ cars = $ this-> Customer_model_update-> getCustomerCars($ customer_id); $数据=数组( 'customer'=> $ customer, '地址'=> $地址, '汽车'=> $汽车 ); $ this-> loadView('customer / upd',$ data); } //更新客户表 公共功能更新($ customer_id){ 回显''; var_dump($_POST); echo ''; // TODO:验证空数组 //构造更新数组 $ customer_data =数组( 'customer_name'=> $ this-> input-> post('customer_name'), 'customer_location'=> $ this-> input-> post('customer_location'), 'customer_phone1'=> $ this-> input-> post('customer_phone1'), 'customer_phone2'=> $ this-> input-> post('customer_phone2'), 'customer_phone3'=> $ this-> input-> post('customer_phone3'), 'customer_phone4'=> $ this-> input-> post('customer_phone4'), 'customer_phone5'=> $ this-> input-> post('customer_phone5'), 'customer_type'=> $ this-> input-> post('customer_type'), 'customer_status'=> 1, 'updated_date'=> date(“ Y-m-d H:i:s”) ); //更新客户详细信息 $ this-> Customer_model_update-> customer_Update($ customer_id,$ customer_data); //更新地址详细信息 $ this-> Customer_model_update-> address_Update($ customer_id); //更新汽车详细信息 $ this-> updateCars($ customer_id); redirect('customer_list'); } 私有函数updateCars($ customer_id){ $ car_id = $ this-> input-> post('car_id'); $ car_type = $ this-> input-> post('car_type'); $ car_model = $ this-> input-> post('car_model'); for($ i = 0; $ iCustomer_model_update-> car_Update($ car_id [$ i],$ car_type [$ i],$ car_model [$ i]); } } //加载视图 公共功能loadView($ view,$ data = array()){ $ this-> load-> view('common / header',$ data); $ this-> load-> view($ view,$ data); $ this-> load-> view('common / footer',$ data); } } ?>
我的模型页面是
Customer_model_update类扩展了CI_Model {
public function __construct(){
// constructor
parent::__construct();
}
public function getCustomer($customer_id) {
$this->db->select('*');
$this->db->from('du_customer');
$this->db->where('customer_id', $customer_id);
$query = $this->db->get();
$result = $query->result();
return $result[0];
}
public function getCustomerAddresses($customer_id) {
$this->db->select('*');
$this->db->from('du_customer_address');
$this->db->where('customer_id', $customer_id);
$query = $this->db->get();
return $query->result();
}
public function getCustomerCars($customer_id) {
$this->db->select('*');
$this->db->from('du_customer_car');
$this->db->where('customer_id', $customer_id);
$query = $this->db->get();
return $query->result();
}
//show all tables
public function showCustomer($customer_id){
$this->db->select('*');
$this->db->from('du_customer');
$this->db->join('du_customer_address','du_customer.customer_id = du_customer_address.customer_id');
$this->db->join('du_customer_car', 'du_customer_address.customer_id = du_customer_car.customer_id');
$this->db->where('du_customer.customer_id', $customer_id);
$query = $this->db->get();
return $query->result();
}
// update data array into du_customer
public function customer_Update($customer_id, $customer_data){
$this->db->where('customer_id',$customer_id);
$this->db->update('du_customer',$customer_data);
}
// update data array into du_customer_address table
public function address_Update($customer_id){
$data = array(
'address_houseno' => $this->input->post('address_houseno'),
'address_street' => $this->input->post('address_street'),
'address_city' => $this->input->post('address_city'),
'address_landmark' => $this->input->post('address_landmark'),
'updated_date' => date("Y-m-d H:i:s")
);
$this->db->where('customer_id',$customer_id);
$this->db->update('du_customer_address',$data);
}
// update data array into du_customer_car_table
public function car_Update($car_id, $car_type, $car_model){
$data = array(
'car_type' => $car_type,
'car_model' => $car_model,
'updated_date' => date("Y-m-d H:i:s")
);
$this->db->where('car_id', $car_id);
$this->db->update('du_customer_car',$data);
}
}
谢谢你们..........