我在这里有一个真正令人头疼的问题。我现在一直在研究Slim API。在我的一条路线中,我从外部.php脚本调用了许多函数。由于某些原因,所有这些功能除了一个......
我使用我所在路线顶部的include('functions.php');
来推荐Slim推荐的外部脚本。
在一个路线中,我连续多次使用这个functions.php
脚本。得到这个,clone_source_directory()
函数执行并按预期返回,update_db_config()
,generate_virtual_host()
和restart_apache()
函数也按预期执行。由于某种原因my_fancy_function()
始终返回错误,无论命名,使用套管等等。
为什么我可以调用位于完全相同脚本中的其他函数,但不能调用my_fancy_function()
?
路由本身应该工作,只是这个函数的执行不合作,这是我的函数调用:
$reply['cloneDir'] = clone_source_directory($ssh, $result['srcCompanyFolderName'], $result['srcPropertyFolderName'], $result['destCompanyFolderName'], $result['destPropertyFolderName']);
$reply['cloneDB'] = my_fancy_function($ssh, $result['srcCompanyFolderName'], $result['srcPropertyFolderName'], $result['destCompanyFolderName'], $result['destPropertyFolderName']); //<-- THIS ONE REFUSES TO WORK
$reply['updateDbConfig'] = update_db_config_file($ssh, $siteToClone->database_name, $result['destCompanyFolderName'], $result['destPropertyFolderName']);
$reply['createVirtualHost'] = generate_virtual_host($ssh, $server, $result['destCompanyFolderName'], $result['destPropertyFolderName']);
$reply['apacheSilentRestart'] = restart_apache($ssh, $server);
为简单起见,我将my_fancy_function()
简化为在执行时返回true
:
function my_fancy_function() {
return true;
}
如果没有来自Slim的不错的神秘错误消息,所有这些都不会是完整的。所以这就是:
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<title>Slim Application Error</title>
<style>body{margin:0;padding:30px;font:12px/1.5 Helvetica,Arial,Verdana,sans-serif;}h1{margin:0;font-size:48px;font-weight:normal;line-height:48px;}strong{display:inline-block;width:65px;}</style>
</head>
<body>
<h1>Slim Application Error</h1>
<p>The application could not run because of the following error:</p>
<h2>Details</h2>
<div>
<strong>Type:</strong> Error
</div>
<div>
<strong>Message:</strong> Call to undefined function my_fancy_function()
</div>
<div>
<strong>File:</strong> /var/www/sites/marc/angus-api/routes/sites.php
</div>
<div>
<strong>Line:</strong> 560
</div>
<h2>Trace</h2>
<pre>#0 [internal function]: Closure->{closure}(Object(Slim\Http\Request), Object(Slim\Http\Response), Array)
#1 /var/www/sites/marc/angus-api/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php(41): call_user_func(Object(Closure), Object(Slim\Http\Request), Object(Slim\Http\Response), Array)
#2 /var/www/sites/marc/angus-api/vendor/slim/slim/Slim/Route.php(344): Slim\Handlers\Strategies\RequestResponse->__invoke(Object(Closure), Object(Slim\Http\Request), Object(Slim\Http\Response), Array)
#3 /var/www/sites/marc/angus-api/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(122): Slim\Route->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response))
#4 /var/www/sites/marc/angus-api/vendor/slim/slim/Slim/Route.php(316): Slim\Route->callMiddlewareStack(Object(Slim\Http\Request), Object(Slim\Http\Response))
#5 /var/www/sites/marc/angus-api/vendor/slim/slim/Slim/App.php(476): Slim\Route->run(Object(Slim\Http\Request), Object(Slim\Http\Response))
#6 /var/www/sites/marc/angus-api/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(122): Slim\App->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response))
#7 /var/www/sites/marc/angus-api/vendor/slim/slim/Slim/App.php(370): Slim\App->callMiddlewareStack(Object(Slim\Http\Request), Object(Slim\Http\Response))
#8 /var/www/sites/marc/angus-api/vendor/slim/slim/Slim/App.php(295): Slim\App->process(Object(Slim\Http\Request), Object(Slim\Http\Response))
#9 /var/www/sites/marc/angus-api/index.php(20): Slim\App->run()
#10 {main}</pre>
</body>
</html>
为什么我似乎无法在functions.php
中创建一个我可以在API路径中执行的新功能的任何建议?