php8.5
Home/ Manual/ yaf / yaf_application/ Yaf_Application::app

Yaf_Application::app

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Retrieve an Application instance

Description

Yaf_Application::app(): Yaf_Application|null

Retrieve the Yaf_Application instance. Alternatively, Yaf_Dispatcher::getApplication can also be used.

Parameters Parameters

Return Values

The Yaf_Application instance, or null if no application has been initialized yet.

Examples

Yaf_Application::app example

php
<?php
/* index.php, the application entry */
$config = new Yaf_Config_Ini(__DIR__ . "/conf/application.ini", "product");
$application = new Yaf_Application($config);
$application->bootstrap()->run();
?>

Retrieving the application instance elsewhere

php
<?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;
    }
}
?>

The above example will output something similar to:

output
string(7) "product"
bool(true)

See Also

  • Yaf_Dispatcher::getApplication

Source: reference/yaf/yaf_application/app.xml · from the official PHP manual (php/doc-en)