0

我正在使用 Zend-framework 3。我想访问控制器中配置文件 (local.php) 的内容。请解释。谢谢大家。

4

2 回答 2

0

您可以执行以下操作(未经测试):

// config.php
return [
   'webhost'  => 'www.example.com',
   'database' => [
     'adapter' => 'pdo_mysql',
     'params'  => [
        'host'     => 'db.example.com',
        'username' => 'dbuser',
        'password' => 'secret',
        'dbname'   => 'mydatabase',
     ],
   ],
];

在你的控制器中:

// Consumes the configuration array
$config = new Zend\Config\Config(include 'config.php');

// Print a configuration datum (results in 'www.example.com')
echo $config->webhost;

假设,你有这个 ZF3 包: zend-config 如果你没有,你必须通过 composer 包含它

composer require zendframework/zend-config
于 2016-10-16T01:14:26.610 回答
0

经过一番研究,我找到了访问任何配置文件的最简单方法。只需在 Module.php $container->get('config')中作为参数之一传递给控制器​​的构造函数,瞧,您现在可以访问控制器中的任何属性。就这么简单。:-) 快乐编码..!!

于 2016-10-17T06:28:23.127 回答