duanqian9503 2016-12-31 16:06
浏览 26

是否有更好的方法来获取应用程序模块类(zend框架)中的basepath

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'))

  • 写回答

1条回答 默认 最新

  • drxdn40242 2017-01-01 11:37
    关注

    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";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错