在我的Silex应用程序中,我需要一个基本上执行file_get_contents()的函数,我的想法是使用如下内容
$app['funky_service'] = function () {
$content = file_get_contents();
return $content;
}这很好用,但是我如何将参数传递给这个函数呢?我可以这样叫它
$fs = $app['funky_service'];但是向它传递参数仍然让我的
发布于 2013-03-17 00:30:12
根据the services chapter in the silex documentation,如果您想要将函数存储为参数,则需要保护函数:
$app['function_parameter'] = $app->protect(function ($resource) {
$content = file_get_contents($resource);
return $content;
});
$example = $app['function_parameter']('http://example.com');https://stackoverflow.com/questions/15450761
复制相似问题