[TYPO3-english] Model seems not to be validated

Henjo Hoeksma | Stylence me at henjohoeksma.nl
Mon Mar 25 00:06:51 CET 2013


Hi Marco, Dirk,

dev list will be fine, mvc list might be better ;-)

@Marco: you do some stuff that gets you into trouble.

public function newAction(Tx_ArArbeitnehmer_**Domain_Model_Employee
> $newEmployee = NULL) {
>      if (empty($newEmployee)) {
>          $newEmployee = $this->createEmptyObject();
>      }
>      $this->view->assign('**newEmployee', $newEmployee);
> }


Why create an emptyObject here? Not needed...

 $this->redirectToUri('/suche/**fuer-arbeitnehmer/ihr-eintrag-**
> vielen-dank.html');

You might want to change this to build an uri with the uri builder and pass
a pageId to that:

$this->uriBuilder->setTargetPageUid($this->settings['thankYouPid']);
$uri = $this->uriBuilder->buildFrontendUri();
$this->redirectToUri($uri);

This is way more flexible and less likely to break.

On validating: you're assigning empty strings to your properties. This way
you are bypassing the validation! Remove the " = ''; " after your
properties and see again!

Kind regards,

Henjo

Problems are small because we learned how to deal with them.
Problems are big because we need to learn how to deal with them.


On Sun, Mar 24, 2013 at 4:16 PM, Dirk Wenzel <wenzel at webfox03.de> wrote:

> Hi Marco,
> you should post your question on the typo3.dev list
>
> Kind regards
> Dirk
>
> Am 20.03.13 08:58, schrieb Marco Behnke:
>
>
>> i,
>>
>> first of all sorry if this is not the right list, but there is no list
>> related to extbase programming (or I did not find it). I tried the
>> extbase team, but got no reply.
>>
>> Yesterday I struggled a lot with creating an extbase extension. Checkbox
>> elements claim that they want booleans and not strings and so on.
>>
>> But my main problem is, that the model does not get validated but
>> insreted into the database which results in query errors because the
>> content is invalid.
>>
>> This is my controller action:
>>
>> /**
>>    * action new
>>    *
>>    * @param Tx_ArArbeitnehmer_Domain_**Model_Employee $newEmployee
>>    * @dontvalidate
>>    * @return void
>>    */
>> public function newAction(Tx_ArArbeitnehmer_**Domain_Model_Employee
>> $newEmployee = NULL) {
>>      if (empty($newEmployee)) {
>>          $newEmployee = $this->createEmptyObject();
>>      }
>>      $this->view->assign('**newEmployee', $newEmployee);
>> }
>>
>> /**
>>    * action create
>>    *
>>    * @param Tx_ArArbeitnehmer_Domain_**Model_Employee $newEmployee
>>    * @return void
>>    */
>> public function createAction(Tx_**ArArbeitnehmer_Domain_Model_**Employee
>> $newEmployee) {
>>      $this->employeeRepository->**add($newEmployee);
>>      $this->flashMessageContainer->**add('Your new Employee was
>> created.');
>>
>>      $this->redirectToUri('/suche/**fuer-arbeitnehmer/ihr-eintrag-**
>> vielen-dank.html');
>> }
>>
>> I tried removing the dontvalidate on the newAction but that results in:
>>
>> Could not ultimately dispatch the request after 101 iterations. Most
>> probably, a @dontvalidate annotation is missing on re-displaying a form
>> with validation errors.
>>
>>
>> This is my model:
>>
>> class Tx_ArArbeitnehmer_Domain_**Model_Employee extends
>> Tx_Extbase_DomainObject_**AbstractEntity {
>>
>>      /**
>>       * Vorname
>>       *
>>       * @var string
>>       * @validate NotEmpty
>>       * @validate StringLength(minimum=1)
>>       */
>>      protected $firstname = '';
>>
>>      /**
>>       * Nachname
>>       *
>>       * @var string
>>       * @validate NotEmpty
>>       * @validate StringLength(minimum=1)
>>       */
>>      protected $lastname = '';
>>
>> ...
>> }
>>
>>
>> I tried it with only NotEmpty and with the StringLength but whatever is
>> entered in there, the model is saved (or at least tried). I would
>> expecte the controller to return with validation errors.
>>
>>
>> What am I doing wrong?
>>
> ______________________________**_________________
> TYPO3-english mailing list
> TYPO3-english at lists.typo3.org
> http://lists.typo3.org/cgi-**bin/mailman/listinfo/typo3-**english<http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-english>
>


More information about the TYPO3-english mailing list