Hallo zusammen,
Ich hätte da eine kleine Frage zum Persistence Manager. Eigentlich sollte es doch möglich sein, wie im unteren Beispiel, ein Objekt aus der Klasse "PersistenceManager" zu instanzieren. Ich verwende Typo3 6.2, Fluid 6.2 und Extbase 6.2. Hier die Beispiel Action.
<?php
namespace Lobacher\Simpleblog\Controller;
/***************************************************************
*
* Copyright notice
*
* (c) 2014 Thomas Schallert <programmierung@sozialinfo.ch>, sozialinfo
*
* 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://ift.tt/iLWIb2.
*
* 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!
***************************************************************/
/**
* BlogController
*/
class BlogController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
/**
* blogRepository
*
* @var \Lobacher\Simpleblog\Domain\Repository\BlogRepository
* @inject
*/
protected $blogRepository;
/**
* persistenceManager
*
* @var \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
* @inject
*/
protected $persistenceManager;
/**
* action list
*
* @return void
*/
public function listAction() {
for ($i=1; $i<=3; $i++) {
$blog = $this->objectManager->get('\\Lobacher\\Simpleblog\\Domain\\Model\\Blog');
$blog->setTitle('Das ist der ' . $i . '. Blog!');
$blog->setDescription('Beschreibung des ' . $i . '. Blogs!');
$this->blogRepository->add($blog);
}
$this->$persistenceManager->persistAll();
$this->view->assign('blogs', $this->blogRepository->findAll());
}
}
?>
Die Fehlermeldung lautet: "Fatal error: Cannot access empty property in /opt/lampp/htdocs/sozialinfo-stellen/typo3conf/ext/simpleblog/Classes/Controller/BlogController.php on line 65". Für mich heisst das, dass das Objekt nicht per Dependency Injection injected wurde. Warum weiss ich nicht. Bin aber draufgekommen, dass es so funktioniert:
<?php
namespace Lobacher\Simpleblog\Controller;
/***************************************************************
*
* Copyright notice
*
* (c) 2014 Thomas Schallert <programmierung@sozialinfo.ch>, sozialinfo
*
* 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://ift.tt/iLWIb2.
*
* 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!
***************************************************************/
/**
* BlogController
*/
class BlogController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
/**
* blogRepository
*
* @var \Lobacher\Simpleblog\Domain\Repository\BlogRepository
* @inject
*/
protected $blogRepository;
protected $persistenceManager;
/**
* action list
*
* @return void
*/
public function listAction() {
for ($i=1; $i<=3; $i++) {
$blog = $this->objectManager->get('\\Lobacher\\Simpleblog\\Domain\\Model\\Blog');
$blog->setTitle('Das ist der ' . $i . '. Blog!');
$blog->setDescription('Beschreibung des ' . $i . '. Blogs!');
$this->blogRepository->add($blog);
}
$this->persistenceManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance("TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager");
$this->persistenceManager->persistAll();
$this->view->assign('blogs', $this->blogRepository->findAll());
}
}
?>
Ist das so sauber oder weiss jemand, warum die Dependency Injection da nicht greift ? Das "$blogRepository" lässt sich nämlich ohne Probleme per Denpendency Injection injecten.
Danke vorab.
Gruss
Thomas
Ich hätte da eine kleine Frage zum Persistence Manager. Eigentlich sollte es doch möglich sein, wie im unteren Beispiel, ein Objekt aus der Klasse "PersistenceManager" zu instanzieren. Ich verwende Typo3 6.2, Fluid 6.2 und Extbase 6.2. Hier die Beispiel Action.
<?php
namespace Lobacher\Simpleblog\Controller;
/***************************************************************
*
* Copyright notice
*
* (c) 2014 Thomas Schallert <programmierung@sozialinfo.ch>, sozialinfo
*
* 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://ift.tt/iLWIb2.
*
* 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!
***************************************************************/
/**
* BlogController
*/
class BlogController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
/**
* blogRepository
*
* @var \Lobacher\Simpleblog\Domain\Repository\BlogRepository
* @inject
*/
protected $blogRepository;
/**
* persistenceManager
*
* @var \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
* @inject
*/
protected $persistenceManager;
/**
* action list
*
* @return void
*/
public function listAction() {
for ($i=1; $i<=3; $i++) {
$blog = $this->objectManager->get('\\Lobacher\\Simpleblog\\Domain\\Model\\Blog');
$blog->setTitle('Das ist der ' . $i . '. Blog!');
$blog->setDescription('Beschreibung des ' . $i . '. Blogs!');
$this->blogRepository->add($blog);
}
$this->$persistenceManager->persistAll();
$this->view->assign('blogs', $this->blogRepository->findAll());
}
}
?>
Die Fehlermeldung lautet: "Fatal error: Cannot access empty property in /opt/lampp/htdocs/sozialinfo-stellen/typo3conf/ext/simpleblog/Classes/Controller/BlogController.php on line 65". Für mich heisst das, dass das Objekt nicht per Dependency Injection injected wurde. Warum weiss ich nicht. Bin aber draufgekommen, dass es so funktioniert:
<?php
namespace Lobacher\Simpleblog\Controller;
/***************************************************************
*
* Copyright notice
*
* (c) 2014 Thomas Schallert <programmierung@sozialinfo.ch>, sozialinfo
*
* 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://ift.tt/iLWIb2.
*
* 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!
***************************************************************/
/**
* BlogController
*/
class BlogController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
/**
* blogRepository
*
* @var \Lobacher\Simpleblog\Domain\Repository\BlogRepository
* @inject
*/
protected $blogRepository;
protected $persistenceManager;
/**
* action list
*
* @return void
*/
public function listAction() {
for ($i=1; $i<=3; $i++) {
$blog = $this->objectManager->get('\\Lobacher\\Simpleblog\\Domain\\Model\\Blog');
$blog->setTitle('Das ist der ' . $i . '. Blog!');
$blog->setDescription('Beschreibung des ' . $i . '. Blogs!');
$this->blogRepository->add($blog);
}
$this->persistenceManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance("TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager");
$this->persistenceManager->persistAll();
$this->view->assign('blogs', $this->blogRepository->findAll());
}
}
?>
Ist das so sauber oder weiss jemand, warum die Dependency Injection da nicht greift ? Das "$blogRepository" lässt sich nämlich ohne Probleme per Denpendency Injection injecten.
Danke vorab.
Gruss
Thomas
Frage zum Persistence Manager