laravel PHPstorm - 无法在blade.php 文件中设置断点

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28501077/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 10:55:38  来源:igfitidea点击:

PHPstorm - Unable to set breakpoints in blade.php files

phpdebugginglaravellaravel-4phpstorm

提问by Don F

I'm working on a Laravel application and can debug my controller php files fine, but Id like to also debug the blade.php files. With my current setup Ive followed all of jetbrains recommend settings for Laravel, (https://confluence.jetbrains.com/display/PhpStorm/Laravel+Development+using+PhpStorm#LaravelDevelopmentusingPhpStorm-DebuggingLaravelApplicationswithPhpStorm) but it is still not allowing my to set breakpoints in the blade.php files.

我正在开发一个 Laravel 应用程序,可以很好地调试我的控制器 php 文件,但我也想调试 Blade.php 文件。使用我当前的设置,我遵循了所有 jetbrains 推荐的 Laravel 设置,(https://confluence.jetbrains.com/display/PhpStorm/Laravel+Development+using+PhpStorm#LaravelDevelopmentusingPhpStorm-DebuggingLaravelApplicationswithPhpStorm)但它仍然不允许我设置Blade.php 文件中的断点。

What could I be missing?

我可能会错过什么?

回答by Alex

Putting a

放一个

<?php xdebug_break(); ?>

into your blade file works pretty well. Even in my tests, PHPstorm jumps to the next PHP statement in some cases.

进入您的刀片文件效果很好。即使在我的测试中,PHPstorm 在某些情况下也会跳转到下一个 PHP 语句。

Why this works:

为什么这样做:

Laravel processes the blade file to a normal PHP file in the cache folder. But the PHP statement xdebug_break();will be transferred there and cause the program to halt at the position you want it to (in the cache file).

Laravel 将刀片文件处理为缓存文件夹中的普通 PHP 文件。但是 PHP 语句xdebug_break();将被转移到那里并导致程序在您想要的位置(在缓存文件中)停止。

回答by Don F

To close this question - phpstorm doesnt support this functionality at the moment. A work around provided by jetbrains support was to add *.blade.php to file type associations under PHP in the IDE settings, however, it still wasnt working for me after doing this.

结束这个问题 - phpstorm 目前不支持这个功能。jetbrains 支持提供的解决方法是将 *.blade.php 添加到 IDE 设置中 PHP 下的文件类型关联,但是,这样做后它仍然对我不起作用。

It appears that they created a youtrack ticket in response to my request, if youd like to encourage jetbrains to work on this please upvote: youtrack.jetbrains.com/issue/WI-26476

似乎他们根据我的要求创建了一张 youtrack 票,如果您想鼓励 jetbrains 进行此工作,请投票youtrack.jetbrains.com/issue/WI-26476

回答by HPage

Even if you can get the IDE to enable breakpoints on the blade files, it won't work - Laravel composes a PHP file from the Blade file - it is this file that is eventually used when the script is run - not the Blade file.

即使你可以让 IDE 在刀片文件上启用断点,它也不会工作——Laravel 从刀片文件组成一个 PHP 文件——最终在脚本运行时使用的是这个文件——而不是刀片文件。

A Work-Around

变通办法

This works for PHPStorm - but something similar might be possible in other IDEs.

这适用于 PHPStorm - 但在其他 IDE 中可能会出现类似的情况。

Laravel (5) stores the composed files under storage/framework/views. These files have random generated file names - so it may be tricky to find the file you want. An easy way is to delete all these temp files and then refresh the page you want to debug. A new file will be created. In PHPstorm you can right-click on the file and select the file's extension type. (Not sure about other IDEs)

Laravel (5) 将组合文件存储在 storage/framework/views 下。这些文件具有随机生成的文件名 - 因此可能很难找到您想要的文件。一个简单的方法是删除所有这些临时文件,然后刷新要调试的页面。将创建一个新文件。在 PHPstorm 中,您可以右键单击文件并选择文件的扩展名类型。(不确定其他IDE)

You will now be able to set breakpoints. Obviously you will need to make the changes in the Blade file - but this will at least help you to figure out what is wrong.

您现在可以设置断点。显然,您需要在 Blade 文件中进行更改 - 但这至少可以帮助您找出问题所在。

**Update: Alex's solution is easier! **

**更新:Alex 的解决方案更简单!**

回答by Alex

As with the recent PHPstorm and Laravel 5.8 this should work now out of the box.

与最近的 PHPstorm 和 Laravel 5.8 一样,这应该是开箱即用的。

https://laravel-news.com/laravel-5-8-blade-template-file-path

https://laravel-news.com/laravel-5-8-blade-template-file-path

回答by David A. Gray

I devised an even better hack, which allows conditional debugging support, so that you aren't stuck with XDebug_break for the rest of eternity.

我设计了一个更好的 hack,它允许有条件的调试支持,这样你就不会在永恒的剩余时间里被 XDebug_break 困住。

The single line expands as follows.

单行扩展如下。

<?php if ( \app\utils\DebugLogger::EnableForBlades ( ) ) xdebug_break ( ) ; ?>

This statement has a couple of unusual features.

这个语句有几个不同寻常的特点。

  1. Since blade files done't have use directives, the method name, \app\utils\DebugLogger::EnableForBlades is fully qualified.
  2. Since blade files seem to lack support for the usual code blocking mechanism, the one-line statement is devoid of braces, and is terminated by a semicolon.
  1. 由于刀片文件没有使用指令,因此方法名称 \app\utils\DebugLogger::EnableForBlades 是完全限定的。
  2. 由于刀片文件似乎缺乏对通常的代码阻塞机制的支持,单行语句没有大括号,并以分号终止。

EnableForBlades is a static method that queries an environment variable (one of those defined in .local.env), returning True if that variable evaluates to True. Otherwise, it returns False, and xdebug_break is suppressed.

EnableForBlades 是一种查询环境变量(在 .local.env 中定义的变量之一)的静态方法,如果该变量的计算结果为 True,则返回 True。否则,它返回 False,并且 xdebug_break 被抑制。