Trouble in paradise: Datamapper malfunctioning in TYPO3 9.5.x with Extbase

Before in previous versions of TYPO3 such as TYPO3 8.7.x, I utilized DataMapper to transform the results from my querybuilder select result into an array of objects successfully. However, when switching to TYPO3 9.5.x, I encountered the error message "Call to a member function buildDataMap() on null".

//MyRepository.php

namespace Vendor\MyExtension\Domain\Repository;

use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper;

/**
 * @param string $search
 *
 * @return array
 */
public function findBySearch($search)
{
    $querybuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_myextension_domain_model_produkt');
    $records = $querybuilder->select('tx_myextension_domain_model_produkt.*')
        ->from('tx_myextension_domain_model_produkt')
        ->orWhere(
            $querybuilder->expr()->like('titel', $querybuilder->createNamedParameter('%' . $search . '%')),
            $querybuilder->expr()->like('untertitel', $querybuilder->createNamedParameter('%' . $search . '%'))
        )
        ->orderBy('titel')
        ->execute()
        ->fetchAll();

    $dataMapper = GeneralUtility::makeInstance(DataMapper::class);
    return $dataMapper->map($this->objectType, $records);
}

Answer №1

Certain classes have dependencies on other objects. This holds true in TYPO3 when properties are marked with @inject or if there is a corresponding injectPropertyName method.

In such scenarios, you should create an instance of the class (DataMapper in this instance) using the ObjectManager.

The typical implementation would be like this:

$dataMapper = GeneralUtility::makeInstance(ObjectManager::class)->get(DataMapper::class);

Answer №2

Due to the deprecation of the get method of ObjectManager in TYPO3 version 10, I now utilize the inject annotation to access the DataMapper instance.

/**
* Datamaper
*
* @var DataMapper
* @TYPO3\CMS\Extbase\Annotation\Inject
*/
protected $dataMapper;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Updating the database table using javascript

I am looking to dynamically update my database based on a condition in JavaScript. Currently, I have been using the following approach: <a href="#" onclick="hello()">Update me</a> <script> function hello(smthing) { if(smthing == true) ...

Avoid opening the page when attempting to log in with jquery, ajax, and php

I am facing an issue with my code. I have a file named "index.html" which contains a login form. Another file called "dash.js" retrieves the username and password from the login form and redirects to "connectdb.php" to check the login credentials with the ...

Is information stored in memcache until it is cleared?

The title of the question pretty much sums it up.. Suppose I run this code: $Cache = new Memcache; $Cache->connect('HOST'); $Cache->set('Information', 'array( "Testing" => "Value, "Anther_Test" => "Another Value ...

Rephrase the ajax call and the data retrieved

I'm struggling to find a solution for writing this code snippet without using async: false,. var imageX; var groupX; $.ajax({ type:'GET', url:'php/myphp.php', dataType:'json', async: false, success: ...

Encountered difficulty parsing json data using cUrl in a PHP script

This is my first time encountering a web service. The JSON data from the .NET server is received and encoded to base64 by the PHP server. The issue I am facing currently is the inability to access each attribute within the data: Array ( [JSONDataResult] ...

Trouble with using AJAX to transfer a JavaScript variable to a PHP file

I need assistance in sending a JavaScript variable to a PHP file for displaying comments on a webpage. While I have successfully sent the JS variable to other PHP files, I'm facing issues when trying to do the same with the comment-list.php file. It ...

Extraction of data post logging into the webpage (modem authentication page)

I am currently working on a project that involves extracting data from a specific webpage. However, in order to access the data I need, I first have to log in to the website. After trying out different scripts and searching for solutions online, I managed ...

Fetch the information, insert following, and trigger a slide toggle

I am new to jQuery and I want to create a sliding table. The original table has 3 levels: <ul class="categories"> <li id="category1">1 element</li> //parentid=0 <li id="category2">2 element</li> //parentid=0 <ul> < ...

Update the CURLOPT_URL parameter to accept user input

As someone new to coding, I have a question about using the CURLOPT_URL function in PHP. How can I input a NIK number and retrieve data from this URL: ? Any help would be appreciated, thank you! php $curl = curl_init(); curl_setopt_array($curl, [ CU ...

Testing a PHPUnit method that accepts an array with variable arguments

Currently, I am faced with a scenario in which I am testing a method that invokes another method from a library. This invoked method requires an array with two specific keys ['id'=>123, 'timestamp'=>microtime()]. While I can pass ...

Encountered an issue with reading the property childnotes of null during data retrieval using ajax in PHP

Hello, I am encountering an error while trying to fetch data using ajax. The error message is "Cannot read property 'childNodes' of null". Can anyone help me identify what might be wrong with my code? I have created a form to search for data with ...

transform regex into an array enclosed in parentheses

Hello there, I seem to be facing an issue in finding a suitable solution for my problem. Within my string, I have the following text: anim(10, <-0.016, -0.006, 0.217>, <0.000, 0.000, 0.707, 0.707>, <0.016, 0.010, 0.012>); I am aiming t ...

Encountering an issue with my code in CodeIgniter

I encountered an error when trying to make an AJAX request in CodeIgniter, unlike the usual process in core PHP where we specify the file URL containing the query. The error I received was net::ERR_SSL_PROTOCOL_ERROR . Here is the JavaScript AJAX code sni ...

Looking to incorporate an HTML domain into $url_activation - Sound like a simple task?

My email contains an activation link, but it is missing part of my URL. Instead of displaying "http://example.com/subcategory/activate?123", it only shows "/subcategory/activate?123". The first bit is missing. I attempted to add the missing part in my PHP ...

Is there a way to eliminate empty arrays from my data?

I'm dealing with this PHP code snippet. public function display_children($parent,$level){ try { $cmd = $this->connection->prepare('SELECT mem,pid from mytree where pid = ?'); $cmd->execute(array($parent)); ...

WAMPserver comes with two separate php.ini files

While trying to adjust the max file size in phpmyadmin for mysql imports, I came across an interesting discovery. It turns out there are actually two php.ini files: one located at C:\wamp\bin\apache\Apache2.4.4\bin (considering the ...

Adjust the group_concat_max_len setting for a PDO query

I would like to share the query I'm working on: $cases = $conn->prepare("SELECT GROUP_CONCAT(text SEPARATOR '|') as texts, year FROM cases GROUP BY year ORDER BY ano DESC"); $cases->execute(); $cases_result = $cases->fetchAll(PDO:: ...

Internet Explorer experiences performance issues when a table containing over 500 rows is being utilized

Can anyone offer advice on speeding up the display of large tables with 500+ rows in Internet Explorer? Here is my current approach: The MySQL query result includes 500+ rows, which I then loop through using a while loop to display: echo "<tr class=& ...

When trying to access the resource route, a blank page is

I am currently in the process of developing a resource controller for CRUD operations in Laravel 5.1. In order to set this up, I made changes to the routes file located at app/Http/routes.php: <?php Route::get('/', function () { return vie ...

Displaying Product Codes on Order Management Admin Page in Prestashop

Can someone assist me with displaying product code data on the Order Management Page in Prestashop? I'm struggling to locate the necessary files. Any help would be greatly appreciated. Thank you in advance. ...