Either with $this->redirect()->toUrl
or with $this->redirect()->toRoute
no redirects when I finish editing a form, but the page is left blank without even showing any errors.
I checked everything, and the class UsersFilter
is the one that gives the problem. If I comment out everything that has to do with the class $filter = new UsersFilter();
, it redirects without problem, but if I leave it, the redirect doesn't work.
This is my code:
public function putAction(){
$this->layout()->setVariable('page_header', 'Editar Usuario');
$this->layout()->setVariable('page_description', 'Editar un usuario en el sistema');
$form = new UsersForm("users_form");
$this->dbAdapter =$this->getServiceLocator()->get('Zend\Db\Adapter');
$users = new Users($this->dbAdapter);
$request = $this->getRequest();
if ($request->isPost()) {
$filter = new UsersFilter();
$form->setInputFilter($filter->getInputFilter());
$form->setData($request->getPost());
if ($form->isValid()) {
$data = $this->request->getPost();
//Obtengo el token del usuario
$actualUser = $users->getUserById($data['id_user']);
$data['token'] = $actualUser['token'];
//Creando un password seguro :)
$bcrypt = new Bcrypt(array(
'salt' => 'Token unico: '.$data['token'],
'cost' => 5)
);
$data['pass'] = $bcrypt->create($data['pass']);
$users->updateUser($data['id_user'], $data);
//No funciona si se ejecuta el validador
return $this->redirect()->toRoute('users');
}
} else {
$id = (int)$this->params()->fromRoute('id', 0);
$user = $users->getUserById($id);
$form->bind($user);
}
$view = new ViewModel(array(
'form' => $form,
));
return $view;
}
I was able to solve it, it was a dummy error.
In the class
class UsersFilter implements InputFilterAwareInterface
at the end of the file I closed the brace like this?>
and after that there were 3 newlines, I removed them and after that everything works without problems.