
Yaf_Application::getConfig 메소드는 Yaf 어플리케이션의 설정 정보를 반환하는 메소드입니다.
getConfig 메소드는 Yaf 어플리케이션의 설정 정보를 객체로 반환합니다. 반환되는 객체는 Zend_Config 객체의 인스턴스입니다.
getConfig 메소드를 호출하여 얻은 데이터를 사용하는 방법은 다음과 같습니다.
#hostingforum.kr
php
$config = Yaf_Application::getConfig();
$host = $config->database->host;
$username = $config->database->username;
$password = $config->database->password;
getConfig 메소드는 파라미터나 옵션을 받지 않습니다.
getConfig 메소드는 Yaf 어플리케이션의 설정 파일을 읽어와 설정 정보를 반환합니다.
Yaf 어플리케이션의 설정 파일은 application.ini 파일입니다.
application.ini 파일의 구조는 다음과 같습니다.
#hostingforum.kr
ini
[database]
host = "localhost"
username = "root"
password = "password"
getConfig 메소드를 사용하여 설정 정보를 얻은 후, 설정 정보를 사용하여 데이터베이스 연결을 생성할 수 있습니다.
#hostingforum.kr
php
$config = Yaf_Application::getConfig();
$host = $config->database->host;
$username = $config->database->username;
$password = $config->database->password;
$dsn = "mysql:host=$host;dbname=mydb";
$dbh = new PDO($dsn, $username, $password);
2025-07-26 00:42