0

This is my controller code..

 $data1['billing_info']=$this->billings->get_info1($billing_id);
    $data2['sale_info']=$this->billings->get_sale_info($billing_id);
    $data3['sale_payment_info']=$this->billings->get_sale_payment_info($billing_id);
    $data['all_modules']=$this->Module->get_all_modules();
    $array=array('data1'=>$data1,
                    'data2'=>$data2,'data3'=>$data3,);
                    print_r($array);
 $this->load->view("billing/form1",$array);

This is my form1.php code

<?php $this->load->view("billing/form_basic_info1"); ?>

So I again want to pass that $array to form_basic_info1 view. So how do I do that??

Kedar B
  • 774
  • 5
  • 18
  • 47
  • FOLLOW THIS URL IT MAY HELP TO U http://stackoverflow.com/questions/8756207/codeigniter-pass-array-from-controller-to-view – Thennarasu Feb 27 '15 at 07:36

2 Answers2

1

By default your sub views have access of the variables of the parent view.

Abhisek Malakar
  • 867
  • 1
  • 10
  • 18
1

In controller e.x you have $array['name'] and in first view you can access to $name, As I know you can't pass whole controller's array to second view. Try this in your view:

//first view
//you have access to $name from controller
$data['new_name'] = array();
foreach($name as $row){
    array_push($data['new_name'], $row->name);
}
//pass $data to other view
Vahid Najafi
  • 4,654
  • 11
  • 43
  • 88
  • @KedarB So, What's the problem now? As I mentioned above, In controller for example you retrieve some data from database. And you put them into a multidimensional array. (Also it's not necessary to use data1, data2,...! just data is enough) then you pass data to first view and there you put them into an array with `foreach` loop. – Vahid Najafi Feb 27 '15 at 09:00