开发者

How to configure Netbeans code entry point when you use mod-rewriting

开发者 https://www.devze.com 2023-01-01 03:43 出处:网络
I am developing a website in PHP and I am using mod-rewrite rules. I want to use the Netbeans Run Configuration (under project properties) to set cod开发者_StackOverflow社区e entry points that looks l

I am developing a website in PHP and I am using mod-rewrite rules. I want to use the Netbeans Run Configuration (under project properties) to set cod开发者_StackOverflow社区e entry points that looks like http://project/news or http://project/user/12

It seems Netbeans have a problem with this and needs an entry point to a physical file like http://project/user.php?id=12

Has anyone found a good way to work around this?


I see your question is a bit old, but since it has no answer, I will give you one.

What I did to solve the problem, was to give netbeans what it wants in terms of a valid physical file, but provide my controller (index.php in this case) with the 'data' to act correctly. I pass this data using a query parameter. Using your example of project being the web site domain and user/12 as the URL, use the following in the NetBeans Run Configuration and arguments boxes. netbeans does not need the ? as it inserts that automatically, see the complete url below the input boxes

Project URL:  http://project

Index File: index.php    *(put your controller name here)*

Arguments:  url=user/12

http://project/index.php?url=user/12

Then in your controller (index.php in this example), test for the url query param and if it exists parse it instead of the actual Server Request, as you would do normally.

I also do not want the above URL to be publically accessible. So, by using an IS_DEVELOPER define, which is true only for configured developer IP addresses, I can control who has access that special url.

If you are trying to debug specific pages, alternatively, you can set the NetBeans run configuration to:

http://project/ 

and debug your project, but you must run through your home page once and since the debugger is now active, just navigate to http://project/user/12 in your browser and NetBeans will debug at that entry point. I found passing through my home page every time a pain, so I use the technique above.

Hopefully that provides enough insight to work with your project. It has worked good for me and if you need more detail, just ask.

EDIT: Also, one can make the Run Configuration Project URL the complete url http://project/user/12 and leave the Index File and Arguments blank and that works too without any special code in controller. (tested in NetBeans 7.1). I think I will start using this method.

0

精彩评论

暂无评论...
验证码 换一张
取 消