Welcome Guest, Not a member yet? Register   Sign In
how to manage DB connections
#3

Knowing if the data/state is ready is often not easy. Codeigniter 4 has an event system you could use, to trigger things when you want them: https://codeigniter4.github.io/userguide...vents.html
I reduced my db calls to the minimum using the resultArray to filter data usign lookup tables created with array_column or array_filter:

// Create a URI => ID mapping
$lookup = array_column($data, 'id', 'uri');
if (isset($lookup['/about'])) {
$id = $lookup['/about'];
echo $id;
}

or when you need all data:
$result = array_filter($data, function($item) use ($searchUri) {
return $item['uri'] === $searchUri;
});

if (!empty($result)) {
$id = reset($result)['id'];
echo $id; // Output: 2
}
good hunting!
Reply


Messages In This Thread
how to manage DB connections - by PaulC - 04-10-2025, 06:04 AM
RE: how to manage DB connections - by SergioDaroca - 04-15-2025, 09:22 AM
RE: how to manage DB connections - by ladyangel - 04-22-2025, 05:34 AM



Theme © iAndrew 2016 - Forum software by © MyBB