Welcome Guest, Not a member yet? Register   Sign In
Making data available in ALL views

(06-15-2021, 12:48 PM)paulkd Wrote:
(06-15-2021, 07:18 AM)SoccerGuy3 Wrote: Thanks everyone for the help. Just needed a push in the right direction. Somewhat new to CI and the community support is great.
Now that it is working/returning data, I wonder if there is a better way to return the data. In my view file I am using:
<?= siteInfo()['leads']; ?>

In my helper file:

if (! function_exists('siteinfo')) {

function siteinfo()
$leadModel = new \App\Models\LeadsModel();
$leads = $leadModel ->where('status != "Closed"')

$custModel = new \App\Models\CustomersModel();
$custs = $custModel ->where('status_customer != "Closed"')

$data = array(
'leads' => $leads,
'customers' => $custs,

return $data;
Any suggestions to make that more efficient or easier to access? Always looking to learn new ways!

Personally, I wouldn't use a helper for what you are doing. I would have the model/database instantiation in a controller that will display the view (or possibly a base controller). The $data would be passed into the view as normal.

As stated back at the beginning, the helper made the most sense as I need it on every page and trying to put it into every controller just is a waste and hard to keep track of. I need the data available on every page load. Open to suggestions, but having to put it into every controller (every function?) is just not realistic for me.

Messages In This Thread
RE: Making data available in ALL views - by SoccerGuy3 - 06-15-2021, 12:59 PM

Theme © iAndrew 2016 - Forum software by © MyBB