2

登録したユーザーを登録済みのページにリダイレクトしようとしていますが、そうしていません。

<?php

class RegisterController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        $form = new Application_Form_Register();
        $form->submit->setLabel('Register');
        $this->view->form = $form;
        if ($this->getRequest()->isPost()) {
            $formData = $this->getRequest()->getPost();
            if ($form->isValid($formData)) {
                $first_name = $form->getValue('first_name');
                $surname = $form->getValue('surname');
                $email = $form->getValue('email');
                $username = $form->getValue('username');
                $password = $form->getValue('password');
                $is_admin = $form->getValue('is_admin');
                $age = $form->getValue('age');
                $gender = $form->getValue('gender');
                $uni = $form->getValue('uni');
                $register = new Application_Model_DbTable_Users();
                $register->addUser($first_name, $surname, $email, $username, $password, $is_admin, $age, $gender, $uni);

            } else {
                $form->populate($formData);
            }
            $route = array('controller'=>'Register', 'action'=>'registered');
                    $this->_helper->redirector->gotoRoute($route);

        }
    }

    public function registeredAction()
    {
        // action body
    }

}

これは私が持っているものです

ありがとう

4

2 に答える 2

2

コントローラでは、次のことができます。

$this->_redirect('/controller/action');
于 2012-05-04T06:11:04.827 に答える
2

私は通常使用しないので、これが問題の原因であるかどうかgotoRoute()はわかりませんが、コントローラー名はすべて小文字にする必要があります。つまり、問題を解決するRegister必要があります。 APIregistergotoRouteAndExit()

別の方法を試すこともできます。アクション/コントローラー間のルーティングには、次の方法が最も便利です。

$this->_helper->redirector('registered');

これにより、同じコントローラーのregisteredActionにリダイレクトされます。別のコントローラーのアクションに移動する場合は、次のようにコントローラーを2番目の引数として追加します。

$this->_helper->redirector('registered', 'register');
于 2012-05-04T07:39:49.230 に答える