I would like to pass request-data to this form-class to validate generic information. I've implemented a component (outsourced for reusability) to bring address data into required model format.
namespace App\Form;
use Cake\Form\Form;
use Cake\Form\Schema;
use Cake\Validation\Validator;
class Foo extends Form {
protected function _buildSchema(Schema $schema) {
return $schema
->addField('foo', 'string')
->addField('bar', 'string');
}
[...]
protected function _execute(array $data) {
// How is it possible to use component-method here?
// e.g. $this->MyAddressComponent->saveData($data);
return true;
}
}
Has anyone an idea what I have to do?
Thanks in advance!
Make your form accept the component in the constructor:
Then instantiate the form from the controller as follows: