[TYPO3-mvc] Typo3 extbase validating custom or manual objects
Gianluca Strafella
gianluca.strafella at webformat.com
Fri Sep 13 14:27:09 CEST 2013
Hi Ganybhat,
in extbase 4.7 (typo3 core 4.7) you can create your model instance and
validate it, using a custom validator.
For example, if you have a validator class with name
Tx_YourExt_Domain_Validation_Model_YourValidatorName and your model
class is Tx_YourExt_Domain_Model_YourModelName, your code could be this:
public function createAction() {
//create new instance
$newInstance =
$this->objectManager->create(Tx_YourExt_Domain_Model_YourModelName);
$validator =
$this->objectManager->create("Tx_YourExt_Domain_Validation_Model_YourValidatorName");
$errorResult = $validator->validate($newInstance);
//do some with result (redirect, etc...)
}
$errorResult is an instance of Tx_Extbase_Error_Result that contains
errors detail. You can also check if your model is valid with
$validator->isValid($newInstance).
Regards,
Gianluca
--
Gianluca Strafella
Software Developer
gianluca.strafella at webformat.com
Tel. +39-0427-926.389
WEBFORMAT srl – www.webformat.com
Via S. Francesco d'Assisi, 6 – 20122 MILANO
Corte Europa, 12 - 33097 SPILIMBERGO (PN)
Il 12/09/2013 14:46, Ganapati Bhat ha scritto:
> 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.
> So how to make the validation of manually created object ?
> It should throw error to form like out-of-the-box features, before add()
> function, if there is a validation error.
>
> Thank you.
>
> Regards,
> Ganybhat
>
More information about the TYPO3-project-typo3v4mvc
mailing list