[eluser]cmroanirgo[/eluser]
[quote author="J-Slim" date="1251272047"]Are you using a MODEL for your DB queries ($query1 and $query2)? If so, I would get your foreach loops like so:
...[snip]...
But I really think you should try a custom helper function or library to hold all the processing code to use in a view easily like $this->table_creator($query1). Maybe the CI Table library might even work for you.[/quote]
Ignoring the above posts, the following is the (approximate) solution I have been using in order to have use of functions within a view:
The controller defines a global array and you place items within that. You
also pass that as the 2nd parameter to load->view:
Code:
$_CONTROLLERVARS = array();
class SomeController extends Controller
{
. . .
function index()
{
$_CONTROLLERVARS['controllervar'] = 'Some Content';
$this->load->view('some_view.php', $_CONTROLLERVARS);
}
}
And in the view page, I access the variable directly where I can, and where I can't, I can use $_CONTROLLERVARS directly:
Code:
<!-- Use Code Igniter variable as normal -->
<h1><?=$controllervar?></h1>
<!-- Use a custom defined global variable otherwise -->
<?php
function write_controllervar()
{
global $_CONTROLLERVARS;
$controllervar = $_CONTROLLERVARS['controllervar'];
return $controllervar;
}
?>
<h1><?=$write_controllervar()?></h1>
I was hoping for a more elegant solution and not some diatribe on why i'm doing it wrong.