(Yaf >=1.0.0)
Yaf_Application::app — 检索 Application 实例
检索 Yaf_Application 实例。 也可以使用 Yaf_Dispatcher::getApplication()。
此函数没有参数。
返回 Yaf_Application 实例,
如果还没有初始化过应用则返回 null。
示例 #1 Yaf_Application::app() 示例
<?php
/* index.php, the application entry */
$config = new Yaf_Config_Ini(__DIR__ . "/conf/application.ini", "product");
$application = new Yaf_Application($config);
$application->bootstrap()->run();
?>示例 #2 在其它地方获取应用实例
<?php
class IndexController extends Yaf_Controller_Abstract
{
public function indexAction()
{
/* Yaf_Application::app() is an alias of getInstance() */
$app = Yaf_Application::app();
var_dump($app->environ());
var_dump(Yaf_Application::getInstance() === $app);
return false;
}
}
?>以上示例的输出类似于:
string(7) "product" bool(true)