簡體   English   中英

TYPO3 Extbase控制器/模型驗證失敗

[英]TYPO3 Extbase Controller/Model Validation fails

環境: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 void
     * @dontvalidate $feUser
     */
    public function registerAction(Tx_Foo_Domain_Model_FeUser $feUser = NULL )

/**
     * @param Tx_Foo_Domain_Model_FeUser $feUser
     * @param string $password2
     * @return void
     */
    public function 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”文本。

問題是:每次我將@validate注釋添加到createAction()方法時,我都會收到此錯誤: An error occurred while trying to call Tx_Foo_Controller_FeUserController->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;        
}

如果有退貨聲明則無關緊要......

我查了一下Tx_Extbase_MVC_Controller_ActionController - > callActionMethod()和整個驗證過程(通過var_dump和debug_backtrace等)來弄清楚這個錯誤發生的原因以及錯誤消息沒有輸出的原因。 這一切都很奇怪......所以也許有人在這里有一個tipp :-)

如果我在我的feUser類的模型中添加@validation標記,如@validate notEmpty,則會出現同樣的錯誤

通過typoscript進行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:當然在問這里之前我搜索了很多東西。

在我的情況下出現此錯誤,因為缺少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

這就是訣竅

在我的情況下,我通過在typoscript設置中注釋這一行解決了這個問題:

config.tx_extbase.features.rewrittenPropertyMapper = 1

你應該始終記住的一件事是,有一個緩存,你不能通過按下按鈕來清理。 Extbase反射緩存會緩存模型和控制器中的所有注釋。 所以在開發過程中,要避免很多挫折,請禁用這個糟糕的事情。

我曾寫過一篇關於它的博客文章: http//www.alexanderschnitzler.de/2012/01/disable-extbase-reflection-cache-during-development-typo3-4-6/

所以請先嘗試一下,然后手動截斷數據庫表cf_extbase_ *

之后請報告錯誤是否仍然存在。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM