Redirect in ZF2 does not work

0

Either with $this->redirect()->toUrl or with $this->redirect()->toRoute does not redirect when I finish editing a form, but the page remains blank without even showing an error.

Review everything, and the UsersFilter class is the problem. If I comment everything that has to do with class $filter = new UsersFilter(); redirects without problem, but if I leave it does not work redirect.

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;
    }
    
asked by albertcito 20.07.2016 в 01:04
source

1 answer

1

I could solve it, it was a dummy error.

In the class class UsersFilter implements InputFilterAwareInterface at the end of the file I closed the key so ?> and after that there were 3 line breaks, I deleted them and after that everything worked without problems.

    
answered by 21.07.2016 / 20:26
source