Media website professional
ZendFramework, Php & Mysql, Jquery, javascript, Css, Html...
Read and write configuration files the format xml with Zend_Config
1. Read ini file.
I have a configuration file /application/configs/db.ini as follows:
www.example.com
pdo_mysql
localhost
root
root
zftraining
www.example.com
pdo_mysql
localhost
vanlanh
123456
zftraining
We use the class to read file Zend_Config_Xml db.xml
public function xmlAction(){ $xml = CONFIG_PATH . '/db.xml'; $section = 'data'; $config = new Zend_Config_Xml($xml, $section); echo '
' . $config->webhost; echo '
' . $config->database->adapter; echo '
' . $config->database->params->username; echo '
'; echo '
'; print_r($config->toArray()); echo '
'; }
Output:
www.example.com pdo_mysql vanlanh Array ( [webhost] => www.example.com [database] => Array ( [adapter] => pdo_mysql [params] => Array ( [host] => localhost [username] => vanlanh [password] => 123456 [dbname] => zftraining ) ) )
2.Write xml file
public function writeXmlAction(){ $data = array( 'global'=>array( 'smtp'=>array( 'parameters'=>array( 'host' => "smtp.example.com", 'port' => "587", 'username' => "jeky11", 'password' => "hyd3", 'security' => "tls", ) ) ), 'data'=>array( 'version' => "1.1" ) ); $config = new Zend_Config_Writer_Xml(); $filename = CONFIG_PATH . '/my01.xml'; $objConfig = new Zend_Config($data); $config->write($filename,$objConfig); }
My01.xml output file:
smtp.example.com
587
jeky11
hyd3
tls
1.1
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment