Welcome Guest, Not a member yet? Register   Sign In
Helpers loading with each include statement
#3

(This post was last modified: 08-09-2021, 04:05 PM by SoccerGuy3.)

Here is the contents of one of my Helpers ("siteinfo") as an example:

PHP Code:
<?php

if (! function_exists('siteinfo')) {

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

 
$futureleads $leadModel ->where('status = "Future Prospect"')
 ->
countAllResults();

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

 
$todoModel = new \App\Models\ToDoModel();
 
$todos $todoModel ->where('assigned_to',current_user()->id)
 ->
where('date_completed',NULL)
 ->
orderBy('date_due')
 ->
findall();

 
$servicesModel = new \App\Models\ServicesModel();
 
$r2i $servicesModel ->where('status_id',1)
 ->
countAllResults();

 
$actives $servicesModel ->where('status_id',2)
 ->
countAllResults();

 
$data = array(
 
'leads' => $leads,
 
'leads_future' => $futureleads,
 
'customers' => $custs,
 
'todos' => $todos,
 
'r2i' => $r2i,
 
'actives' => $actives,
 );

 return 
$data;
 }


How else could I retrieve this type of information on every page? It was previously suggested that helpers were the way to go. I'm somewhat new to this and open to suggestions!

It just dawned on me that those should be individual functions and each called where they are needed. My thought process was backwards on this. I was thinking I was calling this once and loading a "variable" with the information when in fact I am calling this function/helper every time I display one of the elements.
Doh!
Sorry for the silly question.
Reply


Messages In This Thread
RE: Helpers loading with each include statement - by SoccerGuy3 - 08-09-2021, 03:59 PM



Theme © iAndrew 2016 - Forum software by © MyBB