Quantcast
Channel: Insane in the Main Frame
Viewing all articles
Browse latest Browse all 310

Typo3 extbase: inject services

$
0
0

The problem: I create a ViewHelper, which calls a service (calcService) and in this service I want to use another service, named AuthenticationService. I got the following error message:

  1. Fatal error: Call to a member function getUser() on a non-object

The problem is that I tried to call the functions statically instead of inject or via objectManager. When I tried the inject in my CalcService, I got the errormessage above and the reason is, that I called the service in my viewhelper in the wrong way.
WRONG:

  1. use Ophi\OphiSomething\Service\CalcService;
  2. class CalcSomethingViewHelper extends AbstractViewHelper {
  3. public function render($str) {
  4. return CalcService::doSomething($str);
  5. }
  6. }

CORRECT:

  1. use Ophi\OphiSomething\Service\CalcService;
  2. class CalcSomethingViewHelper extends AbstractViewHelper {
  3. /**
  4. * @var \Ophi\OphiSomething\Service\CalcService
  5. * @inject
  6. */
  7. private $calcService;
  8. public function render($str) {
  9. return $this->calcService($str);
  10. }
  11. }

…good to know.


Viewing all articles
Browse latest Browse all 310

Trending Articles