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

about DI integration other base class

How do I integrate the DI Class in other base class file ?

<?php

namespace Phalcon\Engines;

class Logic extends \Phalcon\DI\Injectable
{

    public function __construct()
    {

    }

}

for example : in Controll class , i can use $this->session or $this->request .

<?php

namespace Phalcon\Engines;

use Phalcon\Mvc\Controller as MvcController;

class Controller extends MvcController
{
    public $_request_session = true;

}

how can I use $this->session or $this->request in Logic class .

My English general.Say not clear

thks.

You can also extend this class: Phalcon\Mvc\User\Component https://docs.phalcon.io/en/latest/api/Phalcon_Mvc_User_Component.html

How can i get DI attribute in the Logic class ? i extends Phalcon\Mvc\User\Component in Logic class, but this result object(User\Logics\SessionLogic)[64] protected '_di' => null protected '_dependencyInjector' => null protected '_eventsManager' => null is null



2.1k
Accepted
answer
$di->set("sessionlogic", "SessionLogic");

$loader->registerDir(
    ["your/path" => "your/path/sessionlogic"]
);

or

$loader->registerNameSpace(
    ["your/namespace" => "your/path/sessionlogic"]
);

thank you. issue this problem.

$di->set("sessionlogic", "SessionLogic");

$loader->registerDir(
  ["your/path" => "your/path/sessionlogic"]
);

or

$loader->registerNameSpace(
  ["your/namespace" => "your/path/sessionlogic"]
);