0

I have created extbase extension, there for some reason I need to create object manually in create action.

My create action looks like this,

/**
* action create
*
* @return void
*/
public function createAction() {
$newObj = new \TYPO3\Myext\Domain\Model\Modelname();
$newObj->setMyval('value');
$this->myrepository->add($newObj);
}

Here the problem is its not validating for require field, captcha etc even if I mention @validate NotEmpty in model. So how to make the validation of manually created object ? It should throw error to form like out-of-the-box features. Thank you.

  • 1
    You must NOT use ``new`` in extbase. Please always use the object manager. Also your object should be handed over by the view. AFAIK the validation is not used if you add it manually to the repository. – pgampe Sep 13 '13 at 09:44

2 Answers2

0

Out of the box validation is only triggered on constructing model objects from GET/POST parameters according to your controller actions signature.

jugglefish
  • 61
  • 1
  • 3
0

It should look something like this:

   /**
    * action create
    * @param \TYPO3\Myext\Domain\Model\Modelname $newObject
    * @return void
    */
    public function createAction(\TYPO3\Myext\Domain\Model\Modelname $newObject) {
        $this->myrepository->add($newObj);
    }

Take a look at the extension_builder, create a model and let the new/create action be generated for you. That will give you a good example on the create action as well as on the new action where the form is being rendered.

konsolenfreddy
  • 9,551
  • 1
  • 25
  • 36