Reputation: 9040
Here is what I have so far:
class Module
{
public function onBootstrap(MvcEvent $e)
{
$serviceLocator = $e->getApplication()->getServiceManager();
$viewHelperManager = $serviceLocator->get('ViewHelperManager');
$renderer = $viewHelperManager->getRenderer();
$basePath = $renderer->basePath();
// or $basePath = $renderer->basePath('en'); (passing string)
}
}
Is there a better way to achieve getting the base path? Also take in note i need the ability to pass a concatenated path (not required) ($renderer->basePath('someurlpath')
)
Upvotes: 0
Views: 39
Reputation: 1382
To get the base directory or the "Current Working Directory" you should use the PHP function: get_cwd()
as ZF2 sets up the working directory within your public/index.php
. See the ZF2 skeleton application: index.php
chdir(dirname(__DIR__));
So within your code you can do something like:
$myPath = get_cwd() . "/public/folder";
Upvotes: 1