Zum Inhalt springen

Fatal error: Call to undefined method Gallery\MwGallery\Domain\Model\Bild::findByUid() in .../httpdocs/typo3conf/ext/my_gallery/Classes/Controller/BildController.php on line 80

Erstellt am 7. Januar 2015 · 6 Antworten · letzte Antwort am 7. Januar 2015

Tags: Frage

npre ·

hallo,

ich habe mir eine gallerie gebastelt, wo man bei den bildern einen kommentar einfügen kann. dazu soll es ein formular geben, wo man den kommentar einfügt und dann einfach absendet. dazu hätte ich mir im controller in der insertAction folgenden code eingefügt:

$editEntry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance("Gallery\MwGallery\Domain\Model\Bild");
			$editEntry->findByUid($this->request->getArgument('bild'));
			$editEntry->kommentar('hier der text');
			$this->entryReposirory->update($editEntry);

allerdings erscheint mir dann der fehler: Fatal error: Call to undefined method Gallery\MwGallery\Domain\Model\Bild::findByUid() in .../httpdocs/typo3conf/ext/mw_gallery/Classes/Controller/BildController.php on line 80

ich dachte, dass findByUid() wie findAll() generell als methode zur verfügung steht, oder nicht? habe dann im BildRpository testweise die methode rein:

public function findByUid($uid) {
		$query = $this->createQuery();
		 
		$query->getQuerySettings()->setRespectStoragePage(FALSE);
		$query->matching(	
		$query->equals("uid", $uid)
		);
		 
		return $query->execute();
	}

fehler kommt aber trotzdem. wie muss ich es anstellen, dass ich beim bildeintrag den kommentar dazufügen kann?

danke für eure hilfe!
lg
npre

OnkelEdi ·

Hallöle,

also ich weiß nicht ob das stimmt, aber findAll() und findByUid() wird ja immer in Verbindung mit einem Repository benutzt, oder nicht?

Du versuchst da aber ein Model zu instanzieren und die Methode darauf anzuwenden. Ich weiß nicht ob das geht oder obs was bringt.

Bin mir nicht sicher obs daran lieg, aber vielleicht hilfts dir weiter.

Gruß
Eduard

npre ·

danke für deine antwort. wenn ich auf

$editEntry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('\Gallery\MwGallery\Domain\Repository\BildRepository');

umstelle, erhalte ich folgenden fehler:

#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 .../typo3/sysext/core/Classes/Utility/GeneralUtility.php on line 4431 and defined in .../typo3/sysext/extbase/Classes/Persistence/Repository.php line 75 (More information)

kann mir da jemand weiterhelfen?

OnkelEdi ·

ok,

hast du dann aber auch das repository injected?
also irgendwie:

/**
	 * entryRepository
	 * 
	 * @var \blabla\deineExtension\Domain\Repository\deinRepository
	 * @inject
	 */
	protected $enditEntry = NULL;

du hast ja nur den Pfad ausgetauscht.
Aber vielleicht versteh ich dich da auch vollkommen falsch.
Du willst doch mit findAll oder findByUid Einträge aus deiner Datenbank holen oder nicht?
Wenn ja, glaub ich bist du da grundsätzlich auf dem falschen Weg.

npre ·

danke. hier der controller

<?php
namespace Gallery\MwGallery\Controller;


/***************************************************************
 *
 *  Copyright notice
 *
 *  (c) 2015 
 *
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 *  free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  The GNU General Public License can be found at
 *  http://www.gnu.org/copyleft/gpl.html.
 *
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/

/**
 * BildController
 */
class BildController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {

	/**
	 * bildRepository
	 *
	 * @var \Gallery\MwGallery\Domain\Repository\BildRepository
	 * @inject
	 */
	protected $bildRepository = NULL;
	
	/**
	 * galleryRepository
	 *
	 * @var \Gallery\MwGallery\Domain\Repository\GalleryRepository
	 * @inject
	 */
	protected $galleryRepository = NULL;
	
	/**
	 * kommentarRepository
	 *
	 * @var \Gallery\MwGallery\Domain\Repository\KommentarRepository
	 * @inject
	 */
	protected $kommentarRepository = NULL;

	/**
	 * action list
	 *
	 * @return void
	 */
	public function listAction() {
		$bilds = $this->bildRepository->findAll();
		$this->view->assign('bilds', $bilds);
	}

	/**
	 * action show
	 *
	 * @param \Gallery\MwGallery\Domain\Model\Bild $bild
	 * @return void
	 * @inject \Gallery\MwGallery\Domain\Model\Gallery $gallery
	 */
	public function showAction(\Gallery\MwGallery\Domain\Model\Bild $bild) {
		$this->view->assign('bild', $bild);
		
		$this->view->assign('galleryid', $this->request->getArgument('gallery'));
		
		$galleries = $this->galleryRepository->findAll();
		$this->view->assign('galleries', $galleries);
			
		#$bildeins = $this->galleryRepository->findByUid($this->request->getArgument('bild'));
		#print_r($bildeins);
		
		if($this->request->getArgument('kommentar')) {
			$editEntry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('\Gallery\MwGallery\Domain\Repository\BildRepository');
			$editEntry->findByUid($this->request->getArgument('bild'));
			$editEntry->setBild($this->request->getArgument('kommentar'));
			$this->entryReposirory->update($editEntry);

		}

	}

	/**
	 * action new
	 *
	 * @param \Gallery\MwGallery\Domain\Model\Bild $newBild
	 * @ignorevalidation $newBild
	 * @return void
	 */
	public function newAction(\Gallery\MwGallery\Domain\Model\Bild $newBild = NULL) {
		$this->view->assign('newBild', $newBild);
	}

	/**
	 * action create
	 *
	 * @param \Gallery\MwGallery\Domain\Model\Bild $newBild
	 * @return void
	 */
	public function createAction(\Gallery\MwGallery\Domain\Model\Bild $newBild) {
		$this->addFlashMessage('The object was created. Please be aware that this action is publicly accessible unless you implement an access check. See <a href="http://wiki.typo3.org/T3Doc/Extension_Builder/Using_the_Extension_Builder#1._Model_the_domain" target="_blank">Wiki</a>', '', \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR);
		$this->bildRepository->add($newBild);
		$this->redirect('list');
	}

}
toifel ·

Das Thema "dependency injection" solltest du dir noch mal anschauen, dann wird sicher einiges klarer. Edi hat also schon mal den richtigen Weg zur Lösung beschrieben.

Was noch wichtig ist oder später werden könnte: makeInstance() berücksichtigt prinzipiell keine dependencies - es sollte in Extbase möglichst immer mit dem ObjectManager und der get() Methode gearbeitet werden.

http://wiki.typo3.org/Dependency_Injection