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

(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:
Code:
<?= siteInfo()['leads']; ?>

In my helper file:
Code:
<?php

if (! function_exists('siteinfo')) {

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

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

$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.
Reply


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



Theme © iAndrew 2016 - Forum software by © MyBB