PHP 8.6.0 Beta 3 is available for testing

Yaf_Application::app

(Yaf >=1.0.0)

Yaf_Application::appRetrieve an Application instance

Description

public static function Yaf_Application::app(): ?Yaf_Application

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

Parameters

This function has no parameters.

Return Values

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

Examples

Example #1 Yaf_Application::app() example

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

Example #2 Retrieving the application instance elsewhere

<?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:

string(7) "product"
bool(true)

See Also

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top