Task
Grab user's balance from Database on every new page load. Cannot store in session as there is a bonus system which can add to user's balance while he is logged in.
In the way my page is set up it has 4 parts:
$this->load->view('head'); //Head, meta, css, js
$this->load->view('navbar'); //Strip 50px height at top of page. Has navigation, logout and user balance
$this->load->view('xxx'); //Unique page content
$this->load->view('footer'); //standard footer
I can pass information to the view through the additional parameter:
$this->load->view('navbar', $balance);
However, that means everytime the page is called, I have to call the database from the controller somewhere.
What I am looking for is an idea of how to realize so everytime when I call the navbar view, it automatically calls a controller function which returns user balance.
I imagine something like this:
$this->load->view('navbar', function getBalance() {
return callControllerAndGetBalance();
});
Had a dirty idea of putting an AJAX call in the navbar which on page load calls the controller and then changes the value, but that just seems wrong.
Any ideas?