【发布时间】:2020-04-19 17:41:11
【问题描述】:
我将标准 php 代码从一个名为 test5.php 的文件中提取到一个名为 subscription.blade.php 的文件中。
代码在标准的 php 文件中运行良好并且几乎可以运行 在 Laravel 刀片视图中。提示和关联样式正确显示。但是,一旦将两个数组变量之一输入密码框,它只会给我一个 500 错误。当在标准文件中的刀片外部测试相同的代码时,它可以正常工作。我考虑了 .htaccess 问题,因为一个直接受到影响,而不是另一个,并且在故障排除尝试中空无一物。我当然是 Laravel 的新手。我尝试使用 @php 和 @endphp 指令直接在刀片中使用代码,但没有成功,所以我使用了包含。它似乎不喜欢最后一行感谢您对此的任何见解。
我使用 @include('test5') 将以下代码从 test5.php 拉入到 subscription.blade.php 中
<?php
include('easy-protect.php');
$options = array(
'skin' => 6,
);
protect(array('testing','123456'), $options);
?>
错误日志:
[2020-01-01 21:39:08] local.ERROR: Call to a member function send() on null {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Call to a member function send() on null at /home/www/mywebsite.com/index.php:56)
[stacktrace]
#0 {main}
"}
[2020-01-01 21:39:08] local.ERROR: Uncaught Error: Call to a member function send() on null in /home/www/mywebsite.com/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:123
Stack trace:
#0 /home/www/mywebsite.com/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(100): Illuminate\Foundation\Bootstrap\HandleExceptions->renderHttpResponse(Object(Symfony\Component\Debug\Exception\FatalThrowableError))
#1 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleException(Object(Symfony\Component\Debug\Exception\FatalThrowableError))
#2 {main}
thrown {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalErrorException(code: 1): Uncaught Error: Call to a member function send() on null in /home/www/mywebsite.com/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:123
Stack trace:
#0 /home/www/mywebsite.com/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(100): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->renderHttpResponse(Object(Symfony\\Component\\Debug\\Exception\\FatalThrowableError))
#1 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleException(Object(Symfony\\Component\\Debug\\Exception\\FatalThrowableError))
#2 {main}
thrown at /home/www/mywebsite.com/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:123)
[stacktrace]
#0 {main}
"}
index.php:56
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send(); (This is LINE 56)
$kernel->terminate($request, $response);
HandleExceptions.php:100
/**
* Handle an uncaught exception from the application.
*
* Note: Most exceptions can be handled via the try / catch block in
* the HTTP and Console kernels. But, fatal error exceptions must
* be handled differently since they are not normal exceptions.
*
* @param \Throwable $e
* @return void
*/
public function handleException($e)
{
if (! $e instanceof Exception) {
$e = new FatalThrowableError($e);
}
try {
self::$reservedMemory = null;
$this->getExceptionHandler()->report($e);
} catch (Exception $e) {
//
}
if ($this->app->runningInConsole()) {
$this->renderForConsole($e);
} else {
$this->renderHttpResponse($e); (This is LINE 100)
}
}
HandleExceptions.php:123
/**
* Render an exception as an HTTP response and send it.
*
* @param \Exception $e
* @return void
*/
protected function renderHttpResponse(Exception $e)
{
$this->getExceptionHandler()->render($this->app['request'], $e)->send();(This is Line 123)
}
2020 年 1 月 5 日更新:迄今为止的调查结果:
1。 @adilbo 将代码放在刀片文件的最开头并没有做任何更改。
2。事实上,我从 subscription.blade.php 文件中删除了所有代码,只留下了具有完全相同结果的简单保护代码。这让我相信它是 Laravel 中的一个文件名关联,也许我可以在其中排除但在哪里?
3。我在同一目录中我自己的自定义命名 php 刀片视图中尝试了代码,它工作正常。在特定文件名中使用代码不起作用。我希望这是有道理的。
原因错误:Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException 此路由不支持 POST 方法。支持的方法:GET、HEAD。
【问题讨论】:
-
仅供参考,通常有更多的数组选项,但为了简单起见,我在此处将其删减。
-
你已经尝试过这种方式......我尝试使用
<?php and ?>指令直接在刀片中使用代码。 -
如果您使用的是 laravel 框架,请检查 storage/logs 文件夹中的日志,会有日志请检查该文件中的错误详细信息
-
我已经尝试了
-
我已经按照建议检查了日志。为了这个评论,我将压缩错误输出。 1st -
/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:123。此行专门指此代码/** * Render an exception as an HTTP response and send it. * * @param \Exception $e * @return void */ protected function renderHttpResponse(Exception $e) { $this->getExceptionHandler()->render($this->app['request'], $e)->send(); }@SagarSainkar