I know there are other topics with this question, but that topics didn't resolve my problem.
I'm using Phalcon Incubator to use translations from the database. The translate database adapter is added to the Dependency Injector in the bootstrap. The translator service is available in every controller.
$oDi->setShared('translator', function() use($oDb) {
$oRequest = new Request();
$oTranslator = new Phalcon\Translate\Adapter\Database (
array(
'db' => $oDb,
'language' => $oRequest->getBestLanguage()
)
);
return $oTranslator;
});
I thought everything in the Dependency Injector is also availabe in the Volt templates. I can use other services like session and flashSession in Volt without any problem. But the translator service give me this message:
Notice: Undefined variable: translator
I think I have to add the translator service manually with setDI(), because it is not in the default DI. I added this line to the code, but I still get the Undefined message.
$this->view->setDI($oDi);
This is working, but there must be another solution.
$this->view->setVar('translator', $this->di->getShared('translator'));
Can someone help me?