こんにちは、フォームの検証後に素敵なエラー メッセージを取得しようとしています。extbaseとfluidを使用して、文字列を入力する必要がある名前と電子メール フィールドを持つ単純なエンティティを生成します。私は何も変えませんでした。拡張機能ビルダーから生成されたコードを使用しているだけです。
フィールドを空のままにすると、次の検証エラー通知が表示されます。
An error occurred while trying to call Tx_Adresstest_Controller_AdresseController->createAction()
Validation errors for argument "newAdresse"
newAdresse: Validation errors for property "name" Validation errors for property "email"
2 番目の 2 行は問題ありませんが、最初の行の技術的な通知を取り除くことはできません。これは、ユーザーに表示したいものではありません。
ご協力ありがとうございました!
付録:「フラッシュメッセージ」であることがわかりました。しかし、私は削除したくありませんこれは、「アドレスが正常に保存されました」のように、ユーザーにとって肯定的なフィードバック ソースとしても有益な場合があるためです。
付録:テストするために生成され、使用されたコード:
New.html テンプレート
<f:section name="main">
<h1>New Adresse</h1>
<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 method="post" action="create" name="newAdresse" object="{newAdresse}">
<label for="name">
<f:translate key="tx_adresstest_domain_model_adresse.name" /> <span class="required">(required)</span>
</label><br />
<f:form.textfield property="name" /><br />
<label for="email">
<f:translate key="tx_adresstest_domain_model_adresse.email" /> <span class="required">(required)</span>
</label><br />
<f:form.textfield property="email" /><br />
<f:form.submit value="Create new" />
</f:form>
</f:section>
AddressController.phpコントローラー:
<?php
class Tx_Adresstest_Controller_AdresseController extends Tx_Extbase_MVC_Controller_ActionController {
/**
* adresseRepository
*
* @var Tx_Adresstest_Domain_Repository_AdresseRepository
*/
protected $adresseRepository;
/**
* injectAdresseRepository
*
* @param Tx_Adresstest_Domain_Repository_AdresseRepository $adresseRepository
* @return void
*/
public function injectAdresseRepository(Tx_Adresstest_Domain_Repository_AdresseRepository $adresseRepository) {
$this->adresseRepository = $adresseRepository;
}
// ... stripped other actions ...
/**
* action new
*
* @param $newAdresse
* @dontvalidate $newAdresse
* @return void
*/
public function newAction(Tx_Adresstest_Domain_Model_Adresse $newAdresse = NULL) {
$this->view->assign('newAdresse', $newAdresse);
}
/**
* action create
*
* @param $newAdresse
* @return void
*/
public function createAction(Tx_Adresstest_Domain_Model_Adresse $newAdresse) {
$this->adresseRepository->add($newAdresse);
$this->flashMessageContainer->add('Your new Adresse was created.');
$this->redirect('list');
}
?>
Address.phpモデル:
/**
* name
*
* @var string
* @validate NotEmpty
*/
protected $name;
/**
* email
*
* @var string
* @validate NotEmpty
*/
protected $email;
/**
* Returns the name
*
* @return string $name
*/
public function getName() {
return $this->name;
}
/**
* Sets the name
*
* @param string $name
* @return void
*/
public function setName($name) {
$this->name = $name;
}
/**
* Returns the email
*
* @return string $email
*/
public function getEmail() {
return $this->email;
}
/**
* Sets the email
*
* @param string $email
* @return void
*/
public function setEmail($email) {
$this->email = $email;
}
}
?>