I created an extension using Extension builder called "Events". Also created a frontend plugin. The model created has attributes eventDate and eventtitle. The controller has the actions : Show, List, and New.
I added this plugin to a page. But it does not seem to be working.
Its showing me an error at : $events = $this->eventRepository->findAll(); in the EventController.
The php logs show me the following error : Fatal error: Call to a member function findAll() on a non-object in ../typo3conf/ext/event/Classes/Controller/EventController.php on line 44
The appache logs show me the follwoing error :
Thu May 09 19:19:26 2013] [error] [client ::1] PHP 30. TYPO3\\Event\\Controller\\EventController->listAction() /home/Public/Project/typo3/typo3_src-6.1.0/typo3/sysext/extbase/Classes/Mvc/Controller/ActionController.php:277, referer: http://localhost/Project/typo3/typo3/mod.php?M=web_ViewpageView&id=74
How do I resolve this issue ?
Please check if eventRepository is correctly injected. Check the option "is aggregate root" under "Domain object settings" of the model in the extension builder and check if the file yourext/Classes/Domain/Repository/EventRepository.php has been created. Clearing the cache in backend is required!
The repository need to be injected by either
TYPO3 Version < 6.0
/**
* #var Tx_YourExt_Domain_Repository_EventRepository
*/
protected $eventRepository;
/**
* injectEventRepository
*
* #param Tx_YourExt_Domain_Repository_EventRepository $eventRepository
* #return void
*/
public function injectEventRepository(Tx_YourExt_Domain_Repository_EventRepository $eventRepository) {
$this->eventRepository = $eventRepository;
}
or TYPO3 Version >= 6.0
/**
* eventRepository
*
* #var \YourVendor\YourExtension\Domain\Repository\EventRepository
* #inject
*/
protected $eventRepository;
remember to login logout as well.
sometimes changes won't propagate until you login/logout
or disable/enable the extension.
Related
I tried to follow Moodle’s documentation on how to replace a rendering engine, but it doesn’t work for some reason.
I have created a theme following the documentation steps and Then I created a renderers.php file at the root of my project. I added the following lines of code in the renderers.php file:
class theme_overridetest_core_calendar_renderer extends core_calendar_renderer {
/**
* Disabled creation of the button to add a new event (Was: Creates a button to add a new event)
*
* #param int $courseid
* #param int $day
* #param int $month
* #param int $year
* #return string
*/
protected function add_event_button($courseid, $day=null, $month=null, $year=null) {
return '';
}
}
After reviewing the documentation I read a passage that dissatisfied that this way of proceeding was for the older versions of Moodle, I would like to know the one used for version 4.1
I'm trying to extend this IndexRepository to add my own method for a special search.
In the controller I inject my own IndexRepository with:
use Webian\Iancalendar\Domain\Repository\IndexRepository;
/**
* Inject index repository.
*
* #param IndexRepository $indexRepository
*/
public function injectIndexRepository(IndexRepository $indexRepository)
{
$this->indexRepository = $indexRepository;
}
What I did is working but I get this warning:
PHP Warning
Core: Error handler (BE): PHP Warning: Declaration of Webian\Iancalendar\Controller\
BackendController::injectIndexRepository(Webian\Iancalendar\Domain\Repository\IndexRepository $indexRepository)
should be compatible with HDNET\Calendarize\Controller\
AbstractController::injectIndexRepository(HDNET\Calendarize\Domain\Repository\IndexRepository $indexRepository)
in /typo3conf/ext/iancalendar/Classes/Controller/BackendController.php line 42
That's because I'm using my own Webian\Iancalendar\Domain\Repository\IndexRepository that extends HDNET\Calendarize\Domain\Repository\IndexRepository. If I use the original one the warning doesn't appear but obviously my own method is not called.
How can I avoid that warning?
You should either not extend HDNET\Calendarize\Controller\AbstractController but the default AbstractController of Extbase, then you will need to implement all required logic yourself.
Or you just use a different name for your injection method:
use HDNET\Calendarize\Controller\AbstractController;
use MyNamespace\MyExtension\Domain\Repository\IndexRepository;
class MyController extends AbstractController
{
...
/**
* The index repository.
*
* #var IndexRepository
*/
protected $myIndexRepository;
/**
* Inject index repository.
*
* #param IndexRepository $myIndexRepository
*/
public function injectMyIndexRepository(IndexRepository $myIndexRepository)
{
$this->myIndexRepository = $myIndexRepository;
}
...
class IndexRepository extends \HDNET\Calendarize\Domain\Repository\IndexRepository
{
...
// My method that extends \HDNET\Calendarize\Domain\Repository\IndexRepository functionalities
public function findByStartDate(DateTime $startDate = null, DateTime $endDate = null)
{
...
The method name does not really matter, only that it starts with inject and has a type hint indicating the dependency to inject.
I have an events extension (for TYPO3 9 LTS and 10 LTS), say MyVendor\MyEvents and a Locations extension, say MyVendor\MyLocations.
The Model MyVendor\MyEvents\Domain\Model\Events has a property eventLocation which is defined to be an object of MyVendor\MyLocations\Domain\Model\Locations.
Now I want to make the relation to MyVendor\MyLocations\Domain\Model\Locations optional. I have found a way for the TCA to show a different form field in the backend depending on the MyLocations extension being installed. But I have no idea how to make all the type definitions in the Events model conditional. They are crucial for the extension to work:
namespace MyVendor\MyEvents\Domain\Model
class Events extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
/**
* #var \MyVendor\MyLocations\Domain\Model\Locations
*/
protected $eventLocation = NULL;
/**
* #return \MyVendor\MyLocations\Domain\Model\Locations $eventLocation
*/
public function getEventLocation()
{
return $this->eventLocation;
}
/**
* #param \MyVendor\MyLocations\Domain\Model\Locations $eventLocation
* #return void
*/
public function setEventLocation(\MyVendor\MyLocations\Domain\Model\Locations $eventLocation)
{
$this->eventLocation = $eventLocation;
}
}
In case MyVendor\MyLocations is loaded it needs to be defined as above, in case it isn’t loaded it should be just an integer.
In the TCA I am using if (TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('my_locations')) for showing a different field in the backend form for an event.
The Locations Model is in a separate extension because I am using it in a third extension as well.
In your events extension you could setup a repository for locations. Then you can map this repository to your location extensions model via TypoScript.
I try to use pits_downloadcenter extension with TYPO3 9.5.7 and get the following error when I try to see the page in frontend:
Doctrine\Common\Annotations\AnnotationException [Semantical Error] The
annotation "#void" in method
PITS\PitsDownloadcenter\Controller\DownloadController::forceDownloadAction()
was never imported. Did you maybe forget to add a "use" statement for
this annotation?
I added a pull request to the extension which can be found here: https://github.com/hojaonline/pits_downloadcenter/pull/23/files
The change is fairly easy
--- a/Classes/Controller/DownloadController.php
+++ b/Classes/Controller/DownloadController.php
## -185,7 +185,7 ## public function showAction()
* force download file
* by decrypting the file uid
*
- * #void
+ * #return void
*/
public function forceDownloadAction()
{
I am trying to create something with extbase, but the error-message I get is not very helpful. I took the blog_example extension as a guide. A (maybe) important difference is: I don't have a database table because I want to write a custom domain repository that connects to an external servive through REST.
The actual error message (displayed above the plugin, not as an exception message):
An error occurred while trying to call Tx_MyExt_Controller_SubscriptionController->createAction()
Classes/Controller/SubscriptionController:
Stripped down to the important parts.
class Tx_MyExt_Controller_SubscriptionController extends Tx_Extbase_MVC_Controller_ActionController
{
/**
* #var Tx_MyExt_Domain_Repository_SubscriberRepository
*/
protected $subscriberRepository;
/**
* #return void
*/
public function initializeAction()
{
$this->subscriberRepository = t3lib_div::makeInstance('Tx_MyExt_Domain_Repository_SubscriberRepository');
}
/**
* #param Tx_MyExt_Domain_Model_Subscriber $subscriber
* #dontvalidate $subscriber
* #return string The rendered view
*/
public function newAction(Tx_MyExt_Domain_Model_Subscriber $subscriber = null)
{
$this->view->assign('subscriber', $subscriber);
}
/**
* #param Tx_MyExt_Domain_Model_Subscriber $subscriber
* #return string The rendered view
*/
public function createAction(Tx_MyExt_Domain_Model_Subscriber $subscriber)
{ }
}
Classes/Domain/Model/Subscriber
class Tx_MyExt_Domain_Model_Subscriber extends Tx_Extbase_DomainObject_AbstractEntity
{
/**
* #var string
* #dontvalidate
*/
protected $email = '';
/**
* #param string $email
* #return void
*/
public function setEmail($email)
{
$this->email = $email;
}
/**
* #return string
*/
public function getEmail()
{
return $this->email;
}
}
Resources/Private/Templates/Subscription/new
<f:form action="create" controller="Subscription" objectName="Subscriber" object="{subscriber}" method="post">
<f:form.textfield property="email"></f:form.textfield>
<f:form.submit value="submit"></f:form.submit>
</f:form>
Facts
Adding $subscriber = null removes the message. But $subscriber is null then
A var_dump($this->request->getArguments()); displays the form's fields
There is an index action, and it is also the first action defined in ext_localconf.php
The hints and solutions I found aren't working for me, so I hope someone can guide me into the right direction.
I've got the same bug.
If you pass an Model as argument to an method, it will also validate the model fields.
I've had this annotation on my model property:
/**
*
* #var \string
* #validate NotEmpty
*/
It validates the "#validate" annotation.
The field in the database was empty so i got the error message
An error occurred while trying to call ...
It would be good if there was a better error message.
You need to customize the validation annotation or verify that the property is not empty in the database
Hope it helps somebody
In addtion: check any Validations in your Model and your TCA. If a field is marked as #validate NotEmpty in your Model and is not marked appropriately in the TCA, a record can be saved ignoring the #validate settings in the Model. This can happen if you change the Model and/or TCA after creating records.
An example:
Field 'textfield' is set to not validate, both in the TCA and the Model. You create a new record and save it without filling in the field 'textfield' (you can, it is not set to validate). You then change the Model setting 'textfield' to #validate NotEmpty and then try to show the record on the FE, you will get the error.
The solution for that example:
Simply remove the validation in your Model OR check validations in the TCA and Model so that they work together.
--
A German blog post covers this solution: http://www.constantinmedia.com/2014/04/typo3-extbase-an-error-occurred-while-trying-to-call-anyaction/
just override the template method getErrorFlashMessage in yout controller to provide a custom error message...
/**
* A template method for displaying custom error flash messages, or to
* display no flash message at all on errors. Override this to customize
* the flash message in your action controller.
*
* #return string|boolean The flash message or FALSE if no flash message should be set
* #api
*/
protected function getErrorFlashMessage() {
return 'An error occurred while trying to call ' . get_class($this) . '->' . $this->actionMethodName . '()';
}
classic case of "start over from scratch and it works, and if you compare it you have the same code, though".
I updated the code in the question, maybe it helps someone.