简体   繁体   English

使用PHPStorm使用XDebug调试Codeigniter

[英]Debugging Codeigniter with XDebug using PHPStorm

After setting up XDebug I succeeded in debugging php files with PHPStorm that are directly accessible. 设置XDebug后,我成功调试了可以直接访问PHPStorm的php文件。

But recently I started working with CodeIgniter and I worked through this tutorial . 但最近我开始使用CodeIgniter,我完成了本教程 Now I was wondering if it was possible to debug specific MVC files, controller.php for example. 现在我想知道是否可以调试特定的MVC文件,例如controller.php。 Because after setting a breakpoint and starting to debug the controller file with PHPStorm it of course stated 'No direct script access allowed' since I directly accessed the script. 因为在设置断点并开始使用PHPStorm调试控制器文件之后,它当然声明“不允许直接脚本访问”,因为我直接访问了脚本。

And when accessing the file manually eg http://localhost:63342/01_codeigniter_tutorial/public_html/index.php/controller it just shows a 404 page instead of the usual output shown when not opening it with PHPStorm. 当手动访问文件时,例如http:// localhost:63342 / 01_codeigniter_tutorial / public_html / index.php / controller它只显示404页面而不是显示的常用输出,而不是用PHPStorm打开它。

So I'm wondering is there a specific documentation to read through for debugging CodeIgniter or am I just handling it wrong? 所以我想知道是否有一个特定的文档来读取调试CodeIgniter或我只是处理错误?

Thanks to LazyOne, who enlightened me in the comments I was able to find my mistakes and the solution. 感谢LazyOne,他在评论中启发了我,我能够找到我的错误和解决方案。

The very first reason why a 404 page was shown when browsing the site with PhpStorm, was that I was using PhpStorm's built in web server and not my Apache. 使用PhpStorm浏览网站时显示404页面的第一个原因是我使用的是PhpStorm内置的Web服务器,而不是我的Apache。 And said server doesn't handle mod_rewrite rules (which simplifies URLs) so for sites using CodeIgniter it won't work. 并且说服务器不处理mod_rewrite规则(这简化了URL),因此对于使用CodeIgniter的站点,它将无法工作。 And since the scripts aren't directly accesible it's not possible by simply clicking run in PhpStorm. 由于脚本不能直接访问,因此只需单击PhpStorm中的run即可实现。 So we have to initiate the debug request from the outside/web browser. 所以我们必须从外部/ Web浏览器启动调试请求。

Now 2 things have to be done: 现在有两件事要做:

  • PhpStorm (or your prefered IDE) has to know that a debugging process is about to happen PhpStorm(或您喜欢的IDE)必须知道调试过程即将发生
    • Using PhpStorm you have to toggle the “Start Listening for PHP Debug Connections” button. 使用PhpStorm,您必须切换“开始侦听PHP调试连接”按钮。
    • See more in their documentation 文档中查看更多内容
  • When browsing your site as you normally would (in my case localhost/01_codeigniter_tutorial/public_html/index.php/controlle r) you have to set a XDebug cookie since xdebug will not automatically start a debugging session when you open a script. 像往常一样浏览网站时(在我的情况下是localhost / 01_codeigniter_tutorial / public_html / index.php / controlle r),你必须设置一个XDebug cookie,因为当你打开脚本时xdebug不会自动启动调试会话。
    • The easiest way is to install a Browser add on since you only have to click a button (I used The easiest XDebug for FF) 最简单的方法是安装浏览器添加,因为您只需要单击一个按钮(我使用了最简单的XDebug for FF)
    • Read this for more information 阅读本文以获取更多信息

After everything has been set up, you only need to refresh your page and the IDE should receive your debugging request. 完成所有设置后,您只需刷新页面,IDE就会收到您的调试请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM