I'm trying to create custom functions with parameters within my container but everything I do ends up failing. My current code is as folllows:
$container['myFunction'] = function($container) {
return function($arg) {
return $arg;
};
};
// Called from a route:
echo $this->myFunction("test"); // Call to undefined method Slim\Container::myFunction()
Am I doing something wrong? From what I read online this should be the correct way to define a custom container functions with Slim 3. Any help would be great, thanks!
You need to create an instance of the container service before you can use it.
$myFunc = $this->myFunction;
echo $myFunc('test');
Or on one line:
echo ($this->myFunction)('test');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.