Absolute Pathes / Remote Path Outside Scope?
I'm having trouble figuring out the proper way to set up projects in PHPStorm when using a remote SFTP.
My filesystem structure is such on the server:
/ext
/apps
/testapp
/testapp2
/lib
/classes
If I want to create a project for /testapp, I'm unsure:
1. What should be the main path in the project? /, /ext/, /ext/apps/, or /ext/apps/testapp/
2. Which should be my project root and resource root? I've read through the documentation and I'm still unsure what each does.
3. How do I include/link to /ext/lib/classes? If I set the main path as anything below /ext/, I can't even see the lib folder.
4. Is there a way to tell PHPStorm what the absolute path is on the server? If I do a require('/ext/lib/classes/class.php'), it says not found because on the local machine, the path is not the same.
Any help and any or all of these would be greatly appreciated!
请先登录再写评论。
Hi John,
When talking about project setup we should consider local location, not remote. But lets assume that local = remote.
1) I would definitely go for /ext/apps/testapp/ as you do not want to include and mix other (sub)projects together (because in case you have the same class names, it will create some issues/inconveniences in PhpStorm)
2) Project root = your "main path in the project". The resource root is needed (at least in current form how it is implemented in PhpStorm) only if your website root differs from project root, for example: project root is "/ext/apps/testapp/", but the actual website root folder is "/ext/apps/testapp/web/" (then all other folders will be outside of website which will give some additional security as it will not be directly accessible via URL). In this case I would mark (well -- I actually DO this in my projects) "/ext/apps/testapp/web/" as resource root.
3) There are three ways of doing this in PhpStorm -- it depends what kind of files are in that "/ext/lib/classes/" folder
4) You mean for deployment? If so -- No, as deployment works with relative paths (relative to the home page for that login, of course). For debugging -- yes (Settings | PHP | Mappings), as all paths should be absolute. In any case -- you can always use relative paths instead of hardcoded absolute ... or assemble absolute path at run time (yep, there will be tiny performance penalty, which is almost unnoticeable for average projects - unless it's super busy website when 0.0001ms makes the difference) -- easy to do with single-point entry design (e.g. when all requests are router through single script -- e.g. index.php, where you can define common constants that will be used anywhere in your project) theeven better approahc -- use class autoloading functionality -- this will allow to load class from anywhere so no more include/require statements (except few cases) -- yep, there will be slight "penalty" compared to direct include/require.
In case I misunderstood your questions -- please provide better explained example/text.
Absolutely fantastic answer. I wish all my problems were solved in such an informative way!
Thank you!