[Frage] Query mit foreach auslesen TYPO3-Version: 8.7.9

  • sanktusm sanktusm
    T3PO
    0 x
    29 Beiträge
    0 Hilfreiche Beiträge
    21. 09. 2020, 13:48

    Hallo,
    ich möchte eine Abfrage aus der Datenbank (eine Tabelle) mit foreach auslesen.
    Mein Controller sieht so aus:
    [code]public function listAction()
    {

    if($this->request->hasArgument('search')) {

    $search = $this->request->getArgument('search');

    $coSmartSearches = $this->coSmartSearchRepository->findAll();

    $explode_res = Array();

    foreach($coSmartSearches as $key => $value) {

    $explode_res[$key] = explode('\n',$value);

    }

    die(print_r($explode_res)); //gibt Array ( [0]=> Array ( [0]=> Covisionmedia\CoSmartsearch\Domain\Model\CoSmartSearch:0 ) ) aus

    $field = 'SQL_NO_CACHE tt_content.uid, tt_content.tx_mask_searchkeys, tt_content.tx_mask_zubehoer_list, tt_content.header';
    $from = 'tt_content';
    $where = 'tt_content.header LIKE '."'" . '%' . $search . '%' ."'" . '';
    $groub_by = '';
    $order_by = 'tt_content.header ASC';
    $limit = '';

    $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($field, $from, $where, $groub_by, $order_by, $limit);

    $this->view->assign('coSmartSearches', $res);

    }

    }
    [/code]

    meine Repository so:
    [code]<?php
    namespace Covisionmedia\CoSmartsearch\Domain\Repository;

    /***
    *
    * This file is part of the "covision smart search" Extension for TYPO3 CMS.
    *
    * For the full copyright and license information, please read the
    * LICENSE.txt file that was distributed with this source code.
    *
    * (c) 2020
    *
    ***/

    /**
    * The repository for CoSmartSearches
    */

    use \TYPO3\CMS\Extbase\Persistence\Repository;

    class CoSmartSearchRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
    {

    public function findAll() {

    $query = $this -> createQuery();

    $query->statement('SELECT table_names, table_columns, table_joins FROM tx_cosmartsearch_domain_model_cosmartsearch');

    return $query->execute();

    }

    }
    [/code]


  • 1
  • sanktusm sanktusm
    T3PO
    0 x
    29 Beiträge
    0 Hilfreiche Beiträge
    24. 09. 2020, 14:38

    So geht es:

    public function findAll() {

    $query = $this -> createQuery();

    $query->statement('SELECT tx_cosmartsearch_domain_model_cosmartsearch.table_names, tx_cosmartsearch_domain_model_cosmartsearch.table_columns, tx_cosmartsearch_domain_model_cosmartsearch.table_joins FROM tx_cosmartsearch_domain_model_cosmartsearch');

    return $query->execute(true);

    mit execute (true)

  • 1