Typo3 尝试调用控制器时出错->;createAction()

Typo3 尝试调用控制器时出错->;createAction(),typo3,extbase,Typo3,Extbase,我正试图用extbase创建一些东西,但是我得到的错误消息没有太大帮助。我以blog_示例扩展为指导。一个(可能)重要的区别是:我没有数据库表,因为我想编写一个通过REST连接到外部服务的自定义域存储库 实际错误消息(显示在插件上方,不是异常消息): 尝试调用Tx\u MyExt\u Controller\u SubscriptionController->createAction()时出错 类/控制器/订阅控制器: 精简到重要部分 class Tx_MyExt_Controller_Subs

我正试图用extbase创建一些东西,但是我得到的错误消息没有太大帮助。我以blog_示例扩展为指导。一个(可能)重要的区别是:我没有数据库表,因为我想编写一个通过REST连接到外部服务的自定义域存储库

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

尝试调用Tx\u MyExt\u Controller\u SubscriptionController->createAction()时出错


类/控制器/订阅控制器:
精简到重要部分

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>
Resources/Private/Templates/Subscription/new

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>

事实

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
    将删除消息。但是
    $subscriber
    null
    那么
  • 一个
    var_转储($this->request->getArguments())显示窗体的字段
  • 有一个索引操作,它也是
    ext\u localconf.php

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

经典案例“从头开始,一切顺利,但如果你比较一下,你的代码是一样的”

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

经典的例子是“从头开始,它就工作了,如果你比较一下,你就会得到相同的代码”


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

只需覆盖yout controller中的模板方法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 . '()';
}

只需重写yout controller中的模板方法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 . '()';
}
我也有同样的错误

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

我的模型属性上有以下注释:

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

An error occurred while trying to call ...
如果有更好的错误消息就好了。 您需要自定义验证注释或验证数据库中的属性是否为空

希望它能帮助别人

我也有同样的错误

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

我的模型属性上有以下注释:

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

An error occurred while trying to call ...
如果有更好的错误消息就好了。 您需要自定义验证注释或验证数据库中的属性是否为空


希望它能帮助别人。另外:检查模型和TCA中的任何验证。如果某个字段在您的模型中标记为
@validate NotEmpty
,并且在TCA中没有正确标记,则可以忽略模型中的@validate设置来保存记录。如果在创建记录后更改模型和/或TCA,则可能发生这种情况

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

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

--


一篇德国博文介绍了此解决方案:

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

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

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

--


一篇德国博客文章介绍了这个解决方案:

只是为了验证:您的
订阅者
模型中有getter和setter吗?是的。在问题中添加了setter/getter只是为了验证:您的
订阅者
模型中是否有getter和setter?是的。问题中增加了setter/getter问题不是我想摆脱flash,而是想摆脱阻止插件工作的错误。问题不是我想摆脱flash,而是想摆脱阻止插件工作的错误。是的,你只需要确保存在相应的TCA,除了有效的ext.*.php文件之外。是的,您只需要确保在有效的ext.*.php文件之外存在相应的TCA。这就是我遇到的问题。这也帮助了我。未按照TCA中的要求设置字段,但模型中仍有
*@validate NotEmpty
。详细信息视图失败,尝试调用NAMESPACE\Myext\Controller\ItemController->listAction()
时出错。(显示详细视图的
listAction
的原因是控制器中有一个来自list->detail的转发器)这就是我遇到的问题。这也帮助了我。在TCA中未按要求设置字段,但仍有
*@val