[TYPO3-english] How to instance the model by code in Typo3 6.2.15

Stephan Schuler Stephan.Schuler at netlogix.de
Mon Nov 9 10:37:53 CET 2015


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Hey there.

If you need advanced extbase mechanisms when creating an object (dependency extension, initializeObject() calls), the object manager is the way to go. In general when being in extbase environments, the object manager clearly is what you want to use.
But besides not initializing objects correctly: Both, the object manager as well as GeneralUtility::makeInstance() should at least find your class and create an object.

There are three things that come to my mind directly:
* The „Classes“ fragment is not part of your namespace but only the folder inside your extension where to look at for classes.
* Your extension name should start with an upper case, so „Hockey“ it is.
* So you did call your extension „hockey“?

If you’re on an advanced PHP version (Well. Advanced in terms of TYPO3 requirement, not advanced in terms of PHP in general):
In PHP 5.5 there’s the „::class“ constant. So you might try this:

$hockeyArea = $objectManager->get(\Pharmaline\Hockey\Domain\Model\HockeyArea::class);

This even works with the „use“ statement, which results to this:

use Pharmaline\Hockey\Domain\Model\HockeyArea HockeyArea
$hockeyArea = $objectManager->get(HockeyArea::class);

Regards,



Am [DATE] schrieb "typo3-english-bounces at lists.typo3.org im Auftrag von Christian Platt" <[ADDRESS]>:

>Hi folks,
>
>
>i am trying to import data from xml source into my database.
>So i created a model to import the data. So i need an instance of my data model
>
>
>
>Ín 4.7 extbase i used something like:
>
>$newEntry = t3lib_div::makeInstance('Tx_Phlgallery_Domain_Model_Gallery');
>
>to get en instance from the data model. In 6.2. this does not work anymore. I searched and found, that...
>
>$newHockeyArea=\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Pharmaline\\hockey\\Classes\\Domain\\Model\\HockeyArea');
>
>should do the job, but i get
>Fatal error: Class 'Pharmaline\hockey\Classes\Domain\Model\HockeyArea' not found in /Library/WebServer/Documents/typo62shop/typo3_src-6.2.15/typo3/sysext/core/Classes/Utility/GeneralUtility.php on line 4434
>
>i searched further and found that the object manager should do the job
>
>$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
>
>$newHockeyArea = $objectManager->get('Pharmaline\\hockey\\Classes\\Domain\\Model\\HockeyArea');
>
>With that code it also does not work, i get
>
>1289386765: Could not analyse class:Pharmaline\hockey\Classes\Domain\Model\HockeyArea maybe not loaded or no autoloader? (More information <http://typo3.org/go/exception/CMS/debug/1289386765>)
>
>so, it looks for me that the Model in not found??
>
>What is wrong? Normaly i would get the properties of my Domain  Modell, fill it an add it to my repository….
>
>
>Christian Platt
>
>
>
>

Stephan Schuler
Web-Entwickler | netlogix Web Solutions

Telefon: +49 (911) 539909 - 0
E-Mail: Stephan.Schuler at netlogix.de
Web: websolutions.netlogix.de




netlogix GmbH & Co. KG
IT-Services | IT-Training | Web Solutions
Neuwieder Straße 10 | 90411 Nürnberg
Telefon: +49 (911) 539909 - 0 | Fax: +49 (911) 539909 - 99
E-Mail: info at netlogix.de | Web: http://www.netlogix.de

netlogix GmbH & Co. KG ist eingetragen am Amtsgericht Nürnberg (HRA 13338)
Persönlich haftende Gesellschafterin: netlogix Verwaltungs GmbH (HRB 20634)
Umsatzsteuer-Identifikationsnummer: DE 233472254
Geschäftsführer: Stefan Buchta, Matthias Schmidt




-----BEGIN PGP SIGNATURE-----
Version: PGP Universal 3.3.2 (Build 15917)
Charset: utf-8

wpUDBQFWQGlypp0IwsibV8MBCBv8A/4hyJDmCXjCwExG8kKDZ10Ou2UzyyCErywz
CIdBv4a+cR6C8NUSqfYTaNoLuf+k7aNHgncgRiQS370FArIg1CTvy7PNYfVbzpvJ
hIUsDxiJxpwRPHJMyMmrPrBFsr9vGH1Ry8u4LWbQdcJGYkeqWkicaQtu5HVlumHC
8+AV+S/dag==
=mJbu
-----END PGP SIGNATURE-----


More information about the TYPO3-english mailing list