0
votes

I'm building my first TYPO3 extension, exactly I'm just trying to build the example that is on the TYPO3 page, see link. Looks like something in the controller goes wrong. I'm using the following code

class Tx_Mtclnt_Controller_AdsController
   extends Tx_Extbase_MVC_Controller_ActionController {

   public function listAction() {       

       $adsRepository = t3lib_div::makeInstance('Tx_Mtclnt_Domain_Repository_AdsRepository');
       $ads = $adsRepository->findAll();
       $this->view->assign('ads', $ads);
   }
}

I'm getting the following error:

1: PHP Catchable Fatal Error: Argument 1 passed to TYPO3\CMS\Extbase\Persistence\Repository::__construct() must implement interface TYPO3\CMS\Extbase\Object\ObjectManagerInterface, none given, called in /home/mtclnt02/typo3_src-6.2.9/typo3/sysext/core/Classes/Utility/GeneralUtility.php on line 4431 and defined in /home/mtclnt02/typo3_src-6.2.9/typo3/sysext/extbase/Classes/Persistence/Repository.php line 75 (More information)

TYPO3\CMS\Core\Error\Exception thrown in file /home/mtclnt02/typo3_src-6.2.9/typo3/sysext/core/Classes/Error/ErrorHandler.php in line 101.

1
Is this really 6.2 code ???biesior

1 Answers

1
votes

The error you get results from the repository, which you try to create. The class TYPO3\CMS\Extbase\Persistence\Repository has a constructor, which requires \TYPO3\CMS\Extbase\Object\ObjectManagerInterface as argument. Since you don't pass an objectManager class in your t3lib_div::makeInstance, the error is thrown. You can avoid this, by using dependeny injection like shown below.

/**
 * @var Tx_Mtclnt_Domain_Repository_AdsRepository
 * @inject
 */
protected $adsRepository;

public function listAction() {
  $adsRepository = $this->adsRepository->findAll();
}

But I also see a general problem here, because the Extbase / Fluid book you refer to is outdated on some topics. From my point of view, the refered book is a quite useful resource if you want to understand the concept and architecture of an Extbase/Fluid extension, but not for code examples any more, since a lot of things have changed in TYPO3 since the book has been written.

If you want to start with TYPO3 extension development for TYPO3 6.2 or higher, I would suggest you install the extension extension builder and use it to create your first extension. The manual contains a short but helpful users manual, which guides you through the basics of creating a simple TYPO3 extension.

After you created your first extension with extension builder, you can go some steps further by adding functionality to the code created by extension builer.