Stefan Luv
Stefan Luv

Reputation: 1209

undefined method Controller::forward() in phalcon

Im creating a Controller for all User actions (logIn,logOut,register,etc.) I used forward method in register action and works fine, but, in index action throws undefined method, any idea? I cant find the problem:

use Phalcon\Tag as Tag;
class UserController extends ControllerBase
{

    public function indexAction(){
        Phalcon\Tag::appendTitle("Log In");

        if ($this->request->isPost()) {
            $email = $this->request->getPost('email', 'email');
            $password = $this->request->getPost('password');
            $user = Users::findFirst(
                array(
                    "conditions" =>"email=:email: AND password=:password:",
                    "bind" => array(
                            "email"=>$this->request->getPost('email'),
                            "password"=>$this->request->getPost('password'),
                            )
                    )
                );

            if($user !== FALSE){
                $this->flash->success('Welcome ' . $user->name);
                return $this->forward('user/profile');//Throws undefined forward method
            }else{
                $this->flash->error('Incorrect email or password');
            }
            Tag::setDefault('password', '');
        }
    }
    public function registerAction(){
        $this->assets
             ->addJs("js/jquery.validate.js")
             ->addJs("js/users/register.js");

        if($this->request->isPost()){
            $email = $this->request->getPost("email");
            $password = $this->request->getPost("password");
            $rPassword = $this->request->getPost("rPassword");

            if($password != $rPassword){
                $this->flash->error("Las contraseñas no coinciden");
                return FALSE;
            }

            $user = new Users();
            $user->email = $email;
            $user->password = $password;

            if(!$user->save()){
                foreach($user->getMessages() as $message){
                    $this->flash->error((string)$message);
                }
            }else{
                $this->flash->success('Thanks for register');
                Tag::setDefault('email', '');
                Tag::setDefault('password', '');
                Tag::setDefault('rPassword','');
                return $this->forward('user/index');//Works fine
            }
        }
    }
}

Upvotes: 1

Views: 1057

Answers (2)

Feras Jobeir
Feras Jobeir

Reputation: 36

The forward() is a protected function defined in ControllerBase class:

protected function forward($uri) {

    return $this->response->redirect($uri);

}

Upvotes: 1

Mike Brant
Mike Brant

Reputation: 71384

It would seem that you don't have a method forward() available in UserController or any of its parent hierarchy.

Also, you should be consistent in your use of Phalcon\Tag vs. Tag.

Upvotes: 0

Related Questions