<h1>A_Config_Ini</h1> <p>This example shows using error handler or exceptions. Edit file names to show loading of INI files.</p> <?php include 'config.php'; include '../../A/autoload.php'; $config = new A_Config_Ini('example1.ini', ''); $config->loadFile(); if ($config->isError()) { echo "Error found: loading file<br/>"; } dump($config); $config = new A_Config_Ini('example1.ini', '', new Exception('Ini file error.')); try { $config->loadFile(); } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), '<br/>'; } dump($config);
} } // Basic config data $file_path = dirname($_SERVER['SCRIPT_FILENAME']); $url_path = rtrim(dirname($_SERVER['SCRIPT_NAME']), '/'); if ($url_path == '\\') { $url_path = ''; // fix on Windows } $ConfigArray = array('BASE' => 'http://' . $_SERVER['SERVER_NAME'] . $url_path . '/', 'PATH' => $file_path . '/', 'APP' => $file_path . '/app', 'LIB' => $file_path . '/../../'); // Init autoload using Locator require $ConfigArray['LIB'] . 'A/Locator.php'; $Locator = new A_Locator(); $Locator->autoload(); // Load application config data $Config = new A_Config_Ini('config/example.ini', 'production'); $Config->loadFile(); // import base config array into config object $Config->import($ConfigArray); // set error reporting from config ini_set('error_reporting', $Config->get('ERROR')); // Create HTTP Request object $Request = new A_Http_Request(); // Start Sessions $Session = new A_Session(); //$Session->start(); $UserSession = new A_User_Session($Session); // Dbh $dbconfig = array('phptype' => $Config->get('phptype'), 'database' => $Config->get('database'), 'hostspec' => $Config->get('hostspec'), 'username' => $Config->get('username'), 'password' => $Config->get('password'), 'attr' => array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8", PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC)); $Db = new A_Db_Pdo($dbconfig); $Db->connect();
// Basic config data $file_path = dirname($_SERVER['SCRIPT_FILENAME']); $url_path = rtrim(dirname($_SERVER['SCRIPT_NAME']), '/'); if ($url_path == '\\') { $url_path = ''; // fix on Windows } $ConfigArray = array('BASE' => 'http://' . $_SERVER['SERVER_NAME'] . $url_path . '/', 'PATH' => $file_path . '/', 'APP' => $file_path . '/app', 'LIB' => $file_path . '/../../'); // Configure PHP include path set_include_path($ConfigArray['LIB'] . PATH_SEPARATOR . get_include_path()); // Init autoload using Locator require_once $ConfigArray['LIB'] . 'A/Locator.php'; $Locator = new A_Locator(); $Locator->autoload(); // Load application config data $Config = new A_Config_Ini('config/example.ini', 'production'); $Config->loadFile(); // import base config array into config object $Config->import($ConfigArray); // Create HTTP Request object $Request = new A_Http_Request(); // Create HTTP Response object and set default template and valuesS $Response = new A_Http_Response(); $Response->setTemplate('mainlayout', 'module'); $Response->set('BASE', $ConfigArray['BASE']); $Response->set('title', 'Default Title'); $Response->set('maincontent', 'Default main content set in index.php. If you can see this then none of your controllers gave a value to maincontent or, more likely, you put in a url for which no module/controller/action could be found. I think you should be looking at a 404 page here.'); // Start Sessions $Session = new A_Session(); //$Session->start(); $UserSession = new A_User_Session($Session);