尝试调用 Controller->createAction() 时发生错误

发布于 2025-01-01 03:37:22 字数 2573 浏览 0 评论 0原文

我正在尝试使用 extbase 创建一些东西,但是我收到的错误消息不是很有帮助。我以 blog_example 扩展作为指导。一个(也许)重要的区别是:我没有数据库表,因为我想编写一个通过 REST 连接到外部服务的自定义域存储库。

实际的错误消息(显示在插件上方,而不是作为异常消息):

尝试调用 Tx_MyExt_Controller_SubscriptionController->createAction() 时发生错误


尝试调用 Tx_MyExt_Controller_SubscriptionController->createAction() Classes/Controller/SubscriptionController:
精简到重要部分。

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)
    { }

}

类/域/模型/订阅者

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;
    }
}

资源/私有/模板/订阅/新

<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>

事实

  • 添加 $subscriber = null删除该消息。但是 $subscribernull 然后
  • A var_dump($this->request->getArguments()); 显示表单的字段
  • 有一个索引操作,也是 ext_localconf.php 中定义的第一个操作。

我发现的提示和解决方案对我不起作用,所以我希望有人可以引导我走向正确的方向。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

丑疤怪 2025-01-08 03:37:22

我也有同样的错误。

如果将模型作为参数传递给方法,它也会验证模型字段。

我的模型属性上有这个注释:

/**
 *
 * @var \string
 * @validate NotEmpty
 */

它验证“@validate”注释。
数据库中的字段为空,因此我收到错误消息

An error occurred while trying to call ...

如果有更好的错误消息,那就太好了。
您需要自定义验证注释或验证数据库中的属性不为空

希望它对某人有帮助

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

神回复 2025-01-08 03:37:22

此外:检查您的模型和 TCA 中的所有验证。如果模型中的某个字段被标记为@validate NotEmpty,并且在 TCA 中未正确标记,则可以忽略模型中的 @validate 设置来保存记录。如果您在创建记录后更改模型和/或 TCA,则可能会发生这种情况。

示例:
在 TCA 和模型中,字段“textfield”均设置为不验证。您创建一条新记录并保存它,而无需填写“文本字段”字段(您可以,它未设置为验证)。然后,您将模型设置“textfield”更改为@validate NotEmpty,然后尝试在 FE 上显示记录,您将收到错误。

该示例的解决方案:
只需删除模型中的验证或检查 TCA 和模型中的验证,以便它们协同工作。

--

德国博客文章介绍了此解决方案:http://www.constantinmedia.com/2014/04/typo3-extbase-an-error-occurred-while-trying-to-call-anyaction/

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/

很酷又爱笑 2025-01-08 03:37:22

只需重写 yout 控制器中的模板方法 getErrorFlashMessage 即可提供自定义错误消息...

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

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 . '()';
}
心安伴我暖 2025-01-08 03:37:22

经典案例“从头开始,它可以工作,但如果你比较它,你会得到相同的代码”。

我更新了问题中的代码,也许对某人有帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文