phparrayscodeignitermodel-view-controller

add post data to an array in controller and output from view with Codeigniter


I have the following syntax:

Contoller

  function new_auto_spread_details() 
  {
      $postinfo = array();
      $postinfo[] = $this->input->post('customer')
      $postinfo[] = $this->input->post('period')      
      $this->load->view('sales/new_autospread_order_lines',$postinfo);
  }

View

<?php echo $postinfo['customer']; ?>
<?php echo $postinfo['period']; ?>

This does not output anything. it seems that adding $this->input->post('customer') to the array postinfo is not correct.

How do I correctly add this information to the postinfo array and call it from the view?


Solution

  • function new_auto_spread_details() 
      {
          $postinfo = array();
          $data['postinfo']['customer'] = $this->input->post('customer');
          $data['postinfo']['period'] = $this->input->post('period');     
          $this->load->view('sales/new_autospread_order_lines',$data);
      }
    

    on view

    <?php echo $postinfo['customer']; ?>
    <?php echo $postinfo['period']; ?>