2

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.

2
  • Just to verify: have you got the getter and setter in your Subscriber model? Commented Feb 1, 2012 at 10:59
  • yup. added setter/getter to the question Commented Feb 1, 2012 at 11:37

4 Answers 4

7

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

Sign up to request clarification or add additional context in comments.

2 Comments

That's the problem I had.
This helped me too. A field was not set as required in TCA, but still had * @validate NotEmpty in the model. The detail view failed with An error occurred while trying to call NAMESPACE\Myext\Controller\ItemController->listAction(). (The reason it shows listActionfor the detail view is that there is a forwarder from list -> detail in the controller)
3

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/

Comments

2

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 . '()';
}

1 Comment

the problem isn't that I want to get rid of the flash but to get rid of the error stopping the plugin to work.
1

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.

1 Comment

yes, you just need to make sure that a corresponding TCA is present, beside valid ext_*.php files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.