PHP Conference Japan 2024

Yaf_Application::__construct

(Yaf >=1.0.0)

Yaf_Application::__constructYaf_Application 建構子

說明

public Yaf_Application::__construct(混合 $config, 字串 $envrion = ?)

實例化一個 Yaf_Application

參數

config

一個 ini 設定檔路徑,或是一個設定陣列

如果是 ini 設定檔,則應該有一個以 `yaf.environ` 定義的名稱為名稱的區段,預設為 "product"。

注意事項:

如果您使用 ini 設定檔作為應用程式的設定容器,您應該開啟 `yaf.cache_config` 來提升效能。

以下列出設定項目(及其預設值)

範例 #1 一個 ini 設定檔範例

[product]
;this one should alway be defined, and have no default value
application.directory=APPLICATION_PATH

;following configs have default value, you may no need to define them
application.library = APPLICATION_PATH . "/library"
application.dispatcher.throwException=1
application.dispatcher.catchException=1

application.baseUri=""

;the php script ext name
ap.ext=php

;the view template ext name
ap.view.ext=phtml

ap.dispatcher.defaultModule=Index
ap.dispatcher.defaultController=Index
ap.dispatcher.defaultAction=index

;defined modules
ap.modules=Index

環境

哪個區段將會被載入作為最終設定

回傳值

範例

範例 #2 Yaf_Application::__construct() 範例

<?php
defined
('APPLICATION_PATH') // APPLICATION_PATH 將會在 ini 設定檔中使用
|| define('APPLICATION_PATH', __DIR__));

$application = new Yaf_Application(APPLICATION_PATH.'/conf/application.ini');
$application->bootstrap()->run();
?>

上述範例將會輸出類似以下的內容


範例 #3 Yaf_Application::__construct() 範例

<?php
$config
= array(
"application" => array(
"directory" => realpath(dirname(__FILE__)) . "/application",
),
);

/** Yaf_Application */
$application = new Yaf_Application($config);
$application->bootstrap()->run();
?>

上述範例將會輸出類似以下的內容


另請參閱

新增一則註記

使用者貢獻的註記

此頁面沒有使用者貢獻的註記。
To Top