繁体   English   中英

Zend Framework 2:无法访问命名空间文件中的全局变量

[英]Zend Framework 2: Not being able to access to global vars in namespaced files

我看不到Zend Framework中开发的API的全局变量,我对此感到困惑。

文件系统是这样的:

Project
     Site
         prepend.php (no namespace)
         (many folders of the site) ...
         api
             index.php
             module
                usersApi
                    module.php (namespace UsersApi)
                    src
                       usersApi
                           controller
                                AbstractRestfulJsonController.php (n: UsersApi\Controller)
                                usersController.php (n: UsersApi\Controller)
         core
             config
                config.php
                config.xml

Apache被配置为执行一个前置文件,该文件的目标是加载config.php文件,该文件加载config.xml,因此这意味着在执行每个请求之前,它始终加载所有配置,然后从core_framework_config :: getConfig中检索。 ()-> {{key}}。

问题是我可以在Web服务之外的任何地方获得配置。 实际上,api文件夹中的index.php可以访问core_framework_config及其所有变量,但是当我输入一个命名空间文件(例如userController)时,在类的内部和外部执行该错误,但总是在命名空间文件中执行。 错误是UsersApi \\ Controller \\ core_framework_config方法不存在。 谁能帮我?

UsersController.php:

namespace UsersApi\Controller;

use UsersApi\Controller\AbstractRestfulController;
use Zend\View\Model\JsonModel;

class UsersController extends AbstractRestfulJsonController
{
    public function get($id) {   // Action used for GET requests with resource Id
        // I MUST RELOAD THE CONFIG FILE BECAUSE I CANNOT ACCESS TO CONFIGURED FILE

        $items_per_page = core_framework_config::getConfig()->items_per_page; // this fails with the error mentioned before
    }
}

我通过在开始处添加斜杠来修复它:\\ core_framework_config

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM