Zend Basic Tutorial
Zend Forms
Zend Database
Zend Advanced
Zend Config is a component to read, write, and merge configuration data from various sources like PHP arrays, INI, JSON, or XML files.
It gives you a structured, object-like interface to access configuration settings.
.ini
, .json
, .xml
$config->db->host
)<?php return [ 'name' => 'John', 'db' => [ 'host' => 'localhost', 'user' => 'root', 'password' => 'secret', ], ];
use Laminas\Config\Factory; class MainController extends AbstractActionController { public function homeAction() { $config = Factory::fromFile('config/config.php', true); // Access values echo $config->name; echo $config->db->host; // localhost echo $config->db->user; // root return new ViewModel(); } }
<?php return [ 'name' => 'John', 'db' => [ 'host' => 'localhost', 'user' => 'root', 'password' => 'secret', ], ];
name = "John" [db] host = "localhost" user = "root" pass = "secret"
{ "name": "John", "db": { "host": "localhost", "user": "root", "pass": "secret" } }
<config> <name>John</name> <db> <host>localhost</host> <user>root</user> <pass>secret</pass> </db> </config>
$config1 = [ 'app' => ['name' => 'MyApp', 'debug' => false] ]; $config2 = [ 'app' => ['debug' => true] ]; use Laminas\Config\Config; $conf1 = new Config($config1, true); $conf2 = new Config($config2, true); $conf1->merge($conf2); echo $conf1->app->debug; // true
Use Case |
Example Config File |
Used In |
Config Format |
---|---|---|---|
Application Settings |
|
In controller or service for app metadata |
|
Database Connection |
|
Used to connect via |
|
Mail Configuration |
|
Used in MailService (PHPMailer, etc.) |
|