Hello Phalcon community,
I have been trying to acces a service thru the dependency injection container. What im trying to do is access a class called "Elements". This will hold my common elements. But now i want to access the DI, run a method thru the DI and get a string from that ( Page title ). Now the problem is that the controller does not seem to be able to resolve the DI.
This is my code im using to register my Elements class ( in the bootstrap ):
$di->set('elements', function() use($config){
$element = new Elements(); $element->SetSiteName( $config->web->sitename ); return $element; });
And here is how i utilize it in the controller:
class IndexController extends Controller
{ public function indexAction() { $elements = $this->di->get("elements"); $this->view->content = $elements->getTitle(); } }
For what ever reason my DI keeps being null. And the view is also empty
Full source code:
-
Bootstrap: https://pastebin.com/sGYkunjR
-
Elements: https://pastebin.com/xxbW1QKd
-
Controller: https://pastebin.com/be5vzh5f
- View: https://pastebin.com/RnwFge1H
Using PHP 5.6.3, x86 Windows Xampp Phalcon version 2.0.2 (x86)