【问题标题】:TYPO3 Extbase Controller/Model Validation failsTYPO3 Extbase 控制器/模型验证失败
【发布时间】:2012-06-24 17:43:56
【问题描述】:

环境:Mac OS X Lion、PHP 5.3.10、MySQL 5.X、TYPO3 4.7.1、Extbase 4.7.1、Fluid 4.7.0

这几天我一直在为 extbase 中的一个奇怪的验证错误而苦苦挣扎。

Tx_Foo_Controller_FeUserController 包含以下两个动作:

/** * @param $feUser * @return 无效 * @dontvalidate $feUser */ 公共函数 registerAction(Tx_Foo_Domain_Model_FeUser $feUser = NULL )

/** * @param Tx_Foo_Domain_Model_FeUser $feUser * @param 字符串 $password2 * @return 无效 */ 公共函数 createAction(Tx_Foo_Domain_Model_FeUser $feUser ,$password2 )

两个动作的内容:

$this->view->assign('feUser', $feUser);

register.html 格式如下:

<f:flashMessages />

<f:form.errors>
    <div class="error">
        {error.message}
        <f:if condition="{error.propertyName}">
            <p>
                <strong>{error.propertyName}</strong>:
                <f:for each="{error.errors}" as="errorDetail">
                    {errorDetail.message}
                </f:for>
            </p>
        </f:if>
    </div>
</f:form.errors>        
<f:form object="{feUser}" objectName="feUser" class="form-horizontal" id="fooRegisterForm"
  controller="FeUser" action="create" noCache="1" noCacheHash="1">

     <f:form.textfield type="email" property="email" value="{feUser.email}"/>
    <f:form.textfield property="password" value=""/>
    <f:form.textfield name="password2" value=""/>    
</f:form>

createAction 里面只有一些“OK”文本。

问题是:每次我向 createAction() 方法添加 @validate 注释时,我都会收到此错误: An error occurred while trying to call Tx_Foo_Controller_FeUserController-&gt;createAction()

我使用自定义验证器还是捆绑验证器没有区别。

createAction() 的示例

* @validate $password2 Tx_Extbase_Validation_Validator_IntegerValidator

整数用于引发错误。

自定义验证器类似于 Tx_Foo_Domain_Validator_FeUserValidator,您不必添加 @validation 标记。

自定义验证器:

/**
 * Validation of given Params
 *
 * @param Tx_Foo_Domain_Model_FeUser $feUser
 * @return void
 */
public function isValid($feUser)
{

    $this->addError('Passwords are not RSA strings', 1297418974 );
    return false;        
}

有没有return语句没关系……

我查看了 Tx_Extbase_MVC_Controller_ActionController -> callActionMethod() 和整个验证过程(通过 var_dump 和 debug_backtrace 等),以找出为什么会发生此错误以及为什么错误消息没有输出。这一切都很奇怪......所以也许有人在这里有小费:-)

如果我在我的 feUser 类的模型中添加 @validation 标记,也会出现同样的错误,例如 @validate notEmpty

通过打字稿配置Extbase

config.tx_extbase {
    features.rewrittenPropertyMapper = 1
    persistence{
        storagePid = 5
        enableAutomaticCacheClearing = 1
        updateReferenceIndex = 0
        classes {
            Tx_Foo_Domain_Model_FeUser {
                mapping {
                    tableName = fe_users
                    columns {
                        lockToDomain.mapOnProperty = lockToDomain
                    }
                }
            }
        }
    }
}

非常感谢。

PS:当然,我在这里问之前用谷歌搜索了很多。

【问题讨论】:

  • 只是我在某处的德国 TYPO3 论坛中获得的一个想法。调整注释顺序 - 并在更改后清除临时文件和缓存。
  • 尝试了一切,但没有。下周末我会做进一步调查。

标签: php fluid extbase typo3-flow


【解决方案1】:

在我的情况下,出现此错误,因为缺少 extbase referrer。如果没有referrer,则extbase抛出默认消息。

因为我没有表单,只有一个链接,所以我必须手动添加referrer

/index.php?id=10&tx_bieval_pi1[send]=1&tx_bieval_pi1[hash]=12345&tx_bieval_pi1[__referrer][actionName]=index&tx_bieval_pi1[action]=form&tx_bieval_pi1[controller]=Participation

成功了

【讨论】:

    【解决方案2】:

    在我的例子中,我通过在打字稿设置中注释这一行来解决这个问题:

    config.tx_extbase.features.rewrittenPropertyMapper = 1

    【讨论】:

      【解决方案3】:

      您应该始终牢记的一件事是,有一个缓存,您无法通过按下按钮进行清理。 Extbase 反射缓存缓存了模型和控制器中的所有注释。所以在开发过程中,为了避免很多挫败感,禁用这个糟糕的东西。

      我曾经写过一篇关于它的博客文章: http://www.alexanderschnitzler.de/2012/01/disable-extbase-reflection-cache-during-development-typo3-4-6/

      所以请先试试这个并手动截断数据库表 cf_extbase_*

      如果错误仍然存​​在,请报告。

      【讨论】:

      • 抱歉,缓存从来都不是问题。而且这种缓存也不差。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-10
      • 1970-01-01
      相关资源
      最近更新 更多