We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

EE adds to path of PHP require

Development and Programming

Tim Clarke's avatar
Tim Clarke
2 posts
4 years ago
Tim Clarke's avatar Tim Clarke

Im trying to autoload php from within a template. I have php enabled, but I’m having problems with the path following ‘require_once’. Expression Engine automatically adds ‘ee/legacy/libraries’ to the beginning of the path, which makes

require_once DIR . ‘/folder/vendor/file.php’;

become

require_once DIR . ‘ee/legacy/libraries/folder/vendor/file.php’;

which of course breaks the path. How do I tell EE to stop doing this?

       
Tom Jaeger's avatar
Tom Jaeger
449 posts
4 years ago
Tom Jaeger's avatar Tom Jaeger

Hi Tim,

Generally speaking we discourage the use of PHP in templates. We would recommend going the plugin route (or another add-on option route). If your using version 6 I can shoot over a video that will make it quick to get started with a plugin if you would like?

(FYI, I haven’t tested this) My gut reaction is that this is the current working directory at the time of template processing. You could confirm this with getcwd. So if you choose to go the php in template route, you would likely need to account for this with either adding ../../../ (etc) or changing the present working directory.

Thanks,

-Tom Jaeger

       
vw000's avatar
vw000
482 posts
4 years ago
vw000's avatar vw000

Try using the full absolute path first and see if it works, such as:

require_once DIR . ‘/home/server/domain/folder/vendor/file.php’;

If it works, then start to try how to get there (it might require multiple tries):

require_once DIR . ‘../folder/vendor/file.php’;

require_once DIR . ‘/../folder/vendor/file.php’;

require_once DIR . ‘./../folder/vendor/file.php’;

require_once DIR . ‘../../folder/vendor/file.php’;

I think you get the idea. At some point you will get the relative path.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.