I have a view module that has the html and the javascript for uploading files. I want the scripts to be loaded in the footer (just as an example). So basically the view file should be able to alter the contents of the footer or header. I am attempting to do this by reading the page first into buffer and then outputting the contents into the template file.
My controller has a function that looks like this –
public function test()
{
ob_start();
$this->load->view('content'); // uploader module
ob_end_clean();
$this->load->view('template', array($out1, $out2)); // ideally this will be output into a template file. right now i'm just trying to echo it
}
My uploader module looks like this –
<div>some div for uploading</div>
<?php $out1 = ob_get_contents(); ?>
<?php ob_clean(); ?>
<script>
Logic for uploading that needs to go in the footer
</script>
<?php $out2 = ob_get_contents(); ?>
<?php ob_clean(); ?>
The template file would look like this –
<html>
<body>
<?php echo $out1; ?>
<scripts>other javascript code and includes</script>
<?php echo $out2; ?>
</body>
</html>
However I am unable to save the buffer contents and pass it back into the controller ($out1, $out2). Does anyone know how I can implement this? The goal is basically to delay-load javascript code but have the javascript code reside in the content files to make it easier to code. What’s the best way to do this? Do I need a global array or a new parent controller?
Thanks!
You can pass variables between views like so:
If you run the above code in a view (or a controller, for that matter) ^^, the buffer’s contents will be available in any views which are loaded later as
$my_script.