Urs
Urs

Reputation: 5122

Autoloading / injecting namespaced classes in extbase correctly

I am integrating a few php classes into a TYPO3 6.2 extension created with extension_builder. The extbase version is also 6.2.

I think I followed the indications on https://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Autoloading/Index.html

These are the concerned files:

EXT:apievents/Classes/Utility/SomeClass.php:

class SomeClass {
  // do something
}

EXT:apievents/Classes/Controller/ImportCommandController.php

<?php
namespace STUBR\Apievents\Controller;

// Copyright, Package, License ...

class ImportCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandController {

    /**
    * @var \namespace STUBR\Apievents\Utility\SomeClass
    * @inject
    */
    protected $SomeClass;
    // do something
 }

Which when I run it (it's a scheduler task) gives me the nicely formatted error

Execution of task "Extbase CommandController Task (extbase)" failed with the following message: Could not analyse class:namespace STUBR\Apievents\Utility\SomeClass maybe not loaded or no autoloader?

So something must be missing for the class to be loaded. What am I missing or doing wrong?

Upvotes: 0

Views: 640

Answers (1)

Daniel
Daniel

Reputation: 7016

Change your injection code to

/**
 * @var \STUBR\Apievents\Utility\SomeClass
 * @inject
 */
 protected $someClass;

In the @var annotation you just specify the fully qualified class name. Nothing more. Nothing less. Make sure that you have the namespace set in you utility class as well

namespace STUBR\Apievents\Utility;

Upvotes: 2

Related Questions