Php/docs/yaf-application.construct

提供:Dev Guides
< Php
移動先:案内検索

Yaf_Application::__construct

(Yaf >=1.0.0)

Yaf_Application::__constructYaf_Application のコンストラクタ


説明

public Yaf_Application::__construct ( mixed $config [, string $envrion ] )

Yaf_Application のインスタンスを作成します。


パラメータ

config

ini ファイルへのパス、あるいは設定の配列。

ini ファイルを指定する場合は、 yaf.environ で定義した名前のセクションが必要です。 デフォルトは "product" です。

注意:

ini ファイルをアプリケーションの設定コンテナとして使うのなら、 yaf.cache_config でパフォーマンスを改善できます。 performance.

設定項目とそのデフォルト値の一覧を示します。

例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.defaultModuel=Index
ap.dispatcher.defaultController=Index
ap.dispatcher.defaultAction=index

;defined modules
ap.modules=Index
envrion

最終的な設定として、どのセクションを読み込むか。


返り値

例2 Yaf_Application::__construct() の例

<?phpdefined('APPLICATION_PATH')                  // APPLICATION_PATH が ini ファイルで設定されていれば使います    || define('APPLICATION_PATH', __DIR__)); // __DIR__ は PHP 5.3 で導入されました$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();?>

上の例の出力は、 たとえば以下のようになります。