应用程序在视图中生成损坏的链接(无故停止工作)
Application is generating broken links within the view (stopped working for no reason)
我的完整 Lumen 应用程序在生产系统中没有问题一年后突然停止工作(几乎所有页面都有异常)。由于我没有更改任何代码(至少不是有意识地更改),我想这可能是托管环境中后台更改的问题。
这一切都始于 NotFoundHttpException:
(1/1) NotFoundHttpException
in RoutesRequests.php (line 226)
at Application->handleDispatcherResponse(array(0))
in RoutesRequests.php (line 164)
at Application->Laravel\Lumen\Concerns\{closure}()
in RoutesRequests.php (line 413)
at Application->sendThroughPipeline(array(), object(Closure))
in RoutesRequests.php (line 166)
at Application->dispatch(null)
in RoutesRequests.php (line 107)
at Application->run()
in index.php (line 32)
经过一些研究,我在 SO 上找到了解决方案:
看起来问题可以通过以下方式解决:
$app->run(
$app->make('request')
);
进入index.php.
但是现在我在视图中的所有链接都已损坏 - 示例:
<link rel="icon" type="image/png" sizes="96x96" href="https://:/images/app/favicon-96x96.png">
<link rel="stylesheet" href="https://:/css/base.css">
网址生成于Lumen/src/helpers。php:
/**
* Generate a url for the application.
*
* @param string $path
* @param mixed $parameters
* @param bool $secure
* @return string
*/
function url($path = null, $parameters = [], $secure = null)
{
return app('url')->to($path, $parameters, $secure);
}
似乎所有参数都已正确传递:例如 $path 是 /images/app/apple-icon-57x57.png
,而其他参数为空/null。
更新:搜索了一段时间后我发现:
命名空间Symfony\Component\HttpFoundation;
class Request
{
// ...
/**
* Gets the scheme and HTTP host.
*
* If the URL was called with basic authentication, the user
* and the password are not added to the generated string.
*
* @return string The scheme and HTTP host
*/
public function getSchemeAndHttpHost()
{
return $this->getScheme().'://'.$this->getHttpHost();
}
// ...
}
... 提供了一个错误的方案(没有 SSL)和一个空主机。但是我仍然不知道为什么会这样。
找了一段时间后,我仍然不知道这可能是从哪里来的。有没有人遇到过类似的问题或者可以帮助我解决这个问题?
在 从 Lumen 5.5 更新到 Lumen 5.7 并将 PHP 从 7.0 更新到 7.2.9 之后,部分问题消失了。我仍然必须删除:
$app->make('request')
的解决方案在我的案例中不起作用,仍然存在一些例外情况。还是非常欢迎更好的解决方案或解释!
我的完整 Lumen 应用程序在生产系统中没有问题一年后突然停止工作(几乎所有页面都有异常)。由于我没有更改任何代码(至少不是有意识地更改),我想这可能是托管环境中后台更改的问题。
这一切都始于 NotFoundHttpException:
(1/1) NotFoundHttpException
in RoutesRequests.php (line 226)
at Application->handleDispatcherResponse(array(0))
in RoutesRequests.php (line 164)
at Application->Laravel\Lumen\Concerns\{closure}()
in RoutesRequests.php (line 413)
at Application->sendThroughPipeline(array(), object(Closure))
in RoutesRequests.php (line 166)
at Application->dispatch(null)
in RoutesRequests.php (line 107)
at Application->run()
in index.php (line 32)
经过一些研究,我在 SO 上找到了解决方案:
看起来问题可以通过以下方式解决:
$app->run(
$app->make('request')
);
进入index.php.
但是现在我在视图中的所有链接都已损坏 - 示例:
<link rel="icon" type="image/png" sizes="96x96" href="https://:/images/app/favicon-96x96.png">
<link rel="stylesheet" href="https://:/css/base.css">
网址生成于Lumen/src/helpers。php:
/**
* Generate a url for the application.
*
* @param string $path
* @param mixed $parameters
* @param bool $secure
* @return string
*/
function url($path = null, $parameters = [], $secure = null)
{
return app('url')->to($path, $parameters, $secure);
}
似乎所有参数都已正确传递:例如 $path 是 /images/app/apple-icon-57x57.png
,而其他参数为空/null。
更新:搜索了一段时间后我发现:
命名空间Symfony\Component\HttpFoundation;
class Request
{
// ...
/**
* Gets the scheme and HTTP host.
*
* If the URL was called with basic authentication, the user
* and the password are not added to the generated string.
*
* @return string The scheme and HTTP host
*/
public function getSchemeAndHttpHost()
{
return $this->getScheme().'://'.$this->getHttpHost();
}
// ...
}
... 提供了一个错误的方案(没有 SSL)和一个空主机。但是我仍然不知道为什么会这样。
找了一段时间后,我仍然不知道这可能是从哪里来的。有没有人遇到过类似的问题或者可以帮助我解决这个问题?
在 从 Lumen 5.5 更新到 Lumen 5.7 并将 PHP 从 7.0 更新到 7.2.9 之后,部分问题消失了。我仍然必须删除:
$app->make('request')