【发布时间】:2016-06-10 03:17:03
【问题描述】:
我无法从 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 被配置为执行一个 prepend 文件,其目的是加载 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
}
}
【问题讨论】:
-
$items_per_page = \core_framework_config::getConfig()->items_per_page;? -
是的!你是最棒的!
标签: php zend-framework namespaces zend-framework2