_forward() in Zend does not work?

2019-09-05 04:48发布

问题:

Here is a code:

    public function loginAction()
{
    $form = new Application_Form_Login();
    $this->view->form = $form;

    if($this->_request->isPost())
    {
        self::$dataForm = $this->_request->getPost();
        if($this->form->isValid(self::$dataForm))
        {
            return $this->_forward('authorization');
        } else
        {
            $this->form->populate(self::$form);
        }
    }

}

public function authorizationAction()
{
    if($this->_request->isPost())
    {
        $auth = Zend_Auth::getInstance();
        $authAdapter = new Application_Model_User($this->user->getAdapter(),'user');
        $authAdapter->setIdentityColumn('USERNAME')
                    ->setCredentialColumn('PASSWORD');
        $password = md5(self::$dataForm['password']);
        $authAdapter->setIdentity(self::$dataForm['username']);
        $authAdapter->setCredental($password);

        $result = $auth->authenticate($authAdapter);
        echo 'ok';
        /*
        if($result->isValid())
        {
            //$this->_forward('authorized', 'user');
            echo 'ok';
        }*/
    }
}

Any idea why it does not work? I didn't get any error just blank page.

回答1:

Shouldn't you be calling if($form->isValid(self::$dataForm)) ?



回答2:

As far as I understand it is a bad idea to use the $this->_forward() as it calls the dispatch loop again.

Personally I would place the authorization code into a model class and pass it the username & password from the form.