somejkuser
somejkuser

Reputation: 9040

is there a better way to get the basepath within the application module class (zend framework)

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

Answers (1)

Kwido
Kwido

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

Related Questions