I am working with Zend-framework 3. I want to access the content of config files (local.php) in the controller. please explain. Thank you all in advance.
Asked
Active
Viewed 811 times
2 Answers
0
You can do something like this (it's not tested):
// config.php
return [
'webhost' => 'www.example.com',
'database' => [
'adapter' => 'pdo_mysql',
'params' => [
'host' => 'db.example.com',
'username' => 'dbuser',
'password' => 'secret',
'dbname' => 'mydatabase',
],
],
];
And in your controller:
// Consumes the configuration array
$config = new Zend\Config\Config(include 'config.php');
// Print a configuration datum (results in 'www.example.com')
echo $config->webhost;
Presume, you have this ZF3 package: zend-config If you dont have, you have to include it via composer
composer require zendframework/zend-config

chrki
- 6,143
- 6
- 35
- 55

Ilija Petkovic
- 143
- 2
- 14
0
After some research, I found the simplest way to access any config file. Just in your Module.php pass $container->get('config')
as one of the argument to your controller's constructor and voila you can now access any property in the controller. That much simple. :-) Happy coding..!!

Nitesh
- 823
- 1
- 10
- 15