lets say that i hv this view (main)
<body>
lorem epsim
<div table></div>
lorem epsim
</body>
in controller control1.php i do
$this->load->view('header');
$this->load->view('main',$data);
$this->load->view('footer');
Now i need to load content of div=table from another view (tbl.php),which is called from another controller
control2.php
function load_table(){
$data['x']=1;
$this->load->view('tbl.php',$data);
}
tbl.php view
<ul>$x</ul>
how can i do that ?
i tried to load controler 2 from controller 1 and assign the function load_table to variable and pass that to main view, but it didnt work cuz load->view is executed instead of saving output to variable..
Reason: i need to do this is that tbl.php view is a complex table that i need to refresh and load via ajax calls, so i need it to be on different view alone so can some one explain to me how can i work this out ?
Maybe you can create a view with the table code within and then you can do inside your div for ajax
I've similar needs but mine its like a comments wall for issues.
You can't call one controller method from another, separate controller. You can, however, get the output of the table view and use that:
.
So, you get the data to pass to the tbl.php view and pass that to the load->view method - also passing
TRUE
as the third parameter - which will return the contents of that view as a string (instead of outputting that to the browser). Now, you have a $data variable to pass to themain
view with the table html included and you can just echo that out in the main view.How you get the
$data['table_content']
data from the view is up to you. You can create another controller method inside control1.php, you can create a helper file that can load the view into a string and return that, etc.Inside a view use following in a php block