i am struggling to understand how i can use input filter but i can’t .
firstly i use this video as resource to understand it : “PHP Laminas MVC Web Development - 04d Filtering and Validating Data - YouTube”
i create a CreateForm.php for signup.
my controller :
public function createAction(){
$auth = new AuthenticationService();
if($auth->hasIdentity()){
return $this->redirect()->toRoute('home');
}
$createForm = new CreateForm();
$request = $this->getRequest();
if($request->isPost()){
$formData = $request->getPost()->toArray();
$createForm->setInputFilter($this->authManager->getCreateFormFilter());
$createForm->setData($formData);
if($createForm->isValid()){
try {
$data = $createForm->getData();
$this->authManager->saveAccount($data);
return $this->redirect()->toRoute('home');
} catch (RuntimeException $exception) {
return $this->redirect()->refresh();
}
}
}
$view = new ViewModel([
'form' => $createForm
]);
return $view;
}
my getCreateFormFilter() in my AuthManager.php:
use Laminas\InputFilter\InputFilter;
use Laminas\InputFilter\Factory;
public function getCreateFormFilter(){
$input = new InputFilter();
$factory = new Factory();
$input->add($factory->createInput(['name'=>'username']));
}
i just try to add one element but my editor showing me the message below
qst 1 : is this way correct ??
qst 2 : my editor show me this msg :“Argument ‘1’ passed to createInput() is expected to be of type Laminas\InputFilter\InputProviderInterface|Laminas\InputFilter\InputSpecification|Traversable, array givenPHP(PHP0406)”.I can’t identify the problem