We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

how Get DI services From anyWhere

//  public/index.php
define('BASE_DIR', dirname(__DIR__));
define('APP_DIR', BASE_DIR . '/app');

include APP_DIR . "/config/initialize.php";
$application = new \Phalcon\Mvc\Application($di);
$di['app'] = $application; //  Important
//require_once("../app/library/snowair/phalcon-debugbar/src/ServiceProvider.php");
if ($config->get("application", "environnement") == "production") {
    ini_set('display_errors', 'Off');
    error_reporting(0);
}
else {
    new \Whoops\WhoopsServiceProvider($di);
}

echo $application->handle()->getContent();
// app/config/service.php
$di = new Phalcon\DI\FactoryDefault();
$di->set('session', function() {
    $session = new Phalcon\Session\Adapter\Files();
    if (!isset($_SESSION)) {
        $session->start();
    }
    return $session;
});
// app/controllers/ClassController.php

function updateAction()
{
        Helpers\Famille::updateTaux();
}
// app/componets/helpers/Famille.php
abstract class Famille {

    abstract static function updateTaux()
    {
        // $this is undefined 
        //How can I get the service Session 
    }
}

I want to call the service session into my class Famille . How can I get it ? Thanks !

        $di = \Phalcon\DI::getDefault();
        $request = $di->getRequest();
        $session = $di->getSession();
        ....
edited Nov '17

Thank you , It's work . I have missing to display elements of the session

$di = \Phalcon\DI::getDefault();
$request = $di->getRequest();
$session = $di->get('session');
\Utils::debug($session);  ==> Empty
\Utils::debug($session->personne->id);  => '86'