CodeIgniter - 更新后加载视图

时间:2014-10-29 11:26:01

标签: codeigniter

我更新了客户(工作正常)后

public function update($customer_acc) {

if($this->session->userdata('logged_in'))
 {

    $id= $this->input->post('did');
    $data = array(
    'customer_name' => $this->input->post('dname')
    );
    $this->load->model('update_model');
    $this->update_model->update_customer($id,$data);
 }
else
{
  //If no session, redirect to login page
 redirect('login', 'refresh');
}
}

然后我如何加载视图客户功能。我需要的是在更新完成后再回到查看客户。

public function view($customer_acc) {

if($this->session->userdata('logged_in'))
{

$this->load->model('display_single_customer');
$customers = $this->display_single_customer->view_single_customer($customer_acc);
$data['customer_acc'] = $customers['customer_acc'];
$data['customer_name'] = $customers['customer_name'];

$this->load->view('customers_single_view', $data);
}
else
{
  //If no session, redirect to login page
  redirect('login', 'refresh');
}
}

2 个答案:

答案 0 :(得分:1)

您只需退出控制器中的另一个方法即可显示新页面。传递id你可以直接传递

 if ( some condition ) {

    $id = $this->input->post('did', TRUE);

   // blah blah blah    
   // success -- now go to show customer method

   $this->showCustomer($id)  ; } 


   function showCustomer($id){

      // get the customer to display using the $id that was passed    
      $customers = $this->display_single_customer->view_single_customer($id);

或者您可以使用$ this->声明ID然后它可用于控制器中的任何方法

   $this->id = $this->input->post('did', TRUE);

   // blah blah

  $this->showCustomer()  ; }


 function showCustomer(){

 // get the customer to display using $this->id     
 $customers = $this->display_single_customer->view_single_customer($this->id);

 // etc etc 

答案 1 :(得分:0)

我想我可能已经怀疑我可以使用$ id作为客户帐号进行重定向

redirect("/customers/view/$id");

这是正确的方法,它有效,但这是最佳做法吗?