_forward() in Zend does not work?

倾然丶 夕夏残阳落幕 提交于 2020-01-06 07:22:26

问题


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.



来源:https://stackoverflow.com/questions/5749619/forward-in-zend-does-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!