Firstly, thank you for your reply. It certainly makes sense and fits with the limited results i’d found in previous searches.
Accessing $c from inside my container seems to work (doesn’t throw an error at least), but accessing it from the function is still causing me a problem which I will try to flesh out below…
I’ve got functions stored in my container, as in the example above. I’m building a function now to filter results in server side processing for DataTables, it looks something like…
$container['globalResultsFilter'] = function($c) {
return function($filterType, $filterData, $fieldsData, $sql, $connect) {
// check through arrays passed to the function
// modify and use $sql to retrieve data
// return the data
};
};
it is then called from within the route like…
$connect = $this->db;
$globalResultsFilter = $this->get('globalResultsFilter');
$data = $globalResultsFilter("dataTables", $query, $fieldsData, $baseSql, $connect);
What I want to be able to do is…
$container['globalResultsFilter'] = function($c) {
return function($filterType, $filterData, $fieldsData, $sql, $connect) {
// check through arrays passed to the function
// use $container['checkAccountNumberInput'] (among others) as a function to make sure the user input is what I expected
// modify and use $sql to retrieve data
// return the data
};
};
… Without needing to pass it in to the function from the route (as I am currently doing with the mysql connect string, I understand this is probably the wrong way to do this also).
The filter is currently written into the route directly but I’m going to make more use of it going forward so I’d rather do it using a function or similar so I only have one block of code to maintain, if that makes sense.
Apologies if my question is a little stupid but I’m quite new to this and am struggling to understand the right way to achieve what I’m trying to do. Happy to take a steer on a better approach if you have something I can reference?