Some question about dispatcher forward

ControllerBase.php

<?php
protected function forward($uri){
        $uriParts = explode('/', $uri);
        return $this->dispatcher->forward(
            array(
                'controller' => $uriParts[0], 
                'action' => $uriParts[1]
            )
        );
    }

SessionController.php

.....
if ($password != $rePassword) {
       $this->flash->error('两次输入的密码不一致,请重新输入!');
       return $this->forward('session/register');
}
......

The result----->

两次输入的密码不一致,请重新输入!

两次输入的密码不一致,请重新输入!

两次输入的密码不一致,请重新输入!

两次输入的密码不一致,请重新输入!

两次输入的密码不一致,请重新输入!

两次输入的密码不一致,请重新输入!

两次输入的密码不一致,请重新输入!

两次输入的密码不一致,请重新输入!

...........

两次输入的密码不一致,请重新输入!

Dispatcher has detected a cyclic routing causing stability problems

I can't find the way to debug the question, help me!

Please, can you show us the code in SessesionController::registerAction ?



8.0k
edited May '14
/**
     * 用户注册
     * @return [type] [description]
     */
    public function registerAction() {
        $request = $this->request;
        if ($request->isPost()) {
            $username = $request->getPost('username', array('email', 'email'));
            $password = $request->getPost('password');
            $rePassword = $request->getPost('repassword');
            $sex = $request->getPost('sex', array('int'));

            if ($password != $rePassword) {
                $this->flash->error('两次输入的密码不一致,请重新输入!');
                return $this->forward('session/register');
            }

            $user = new Model\User();
            $user->u_username = $username;
            $user->u_password = sha1($password);
            $user->u_email = $username;
            if ($user->save() == false) {
                foreach ($user->getMessage() as $msg) {
                    $this->flash->error((string) $msg);
                }
                return $this->forward('session/register');
            } else {
                Tag::setDefault('username', '[email protected]');
                Tag::setDefault('password', '');
                Tag::setDefault('sex', 1);
                $this->flash->success('欢饮加入我们的团队,您的宝宝将万众瞩目下成长!');
                return $this->forward('index/index');
            }
        }
    }
edited May '14

Actually it's very simple.

When you forward, you keep the same POST data.

Forwarding is just a way to execute another action with the same request (the same post/get data, same http header etc...) then when you save user, you forward again on register, with the same post data (it means that you still ask to register the user), then you do the same job : register user, forward, register user, forward, register user , forward.

Instead you may use $this->request->redirect or forward to another action. The request->redirect will end the actual script, send a 301 http status (or 302) and the client will load your script once again, but w/o the post datas



8.0k

E.....Understand......Thank for your replay!