在linux服务器上的实时站点上的zend framework-2项目中,路由重定向不起作用


Redirect on route is not work in zend framework-2 project on live site on linux server

我遇到了一个问题,将一个操作重定向到实时站点上的另一个操作。(http://marwarishaadicentre.in/)我在Authenticate Action中发布了此代码中的Auth Controller代码。它可以成功进行身份验证,但不能在管理员或配置文件路由上重定向。

 public function authenticateAction()
{
    $user_session = new Container('user');
        $form = $this->getForm();
        $redirect = 'member/login';
        $request = $this->getRequest();
        if($request->isPost())
        {
            $form ->setData($request->getPost());
            if($form->isValid())
            {
                $username = $request->getPost('username');
                $password = $request->getPost('password');
                $credential = $this->getAuthService()->getAdapter()
                                   ->setIdentity($request->getPost('username'))
                                   ->setCredential($request->getPost('password'));
                $is_active = $this->getUserTable()->checkActivation($username,$password);
                $is_admin = $this->getUserTable()->checkAdmin($username);
                 $is_verify = $this->getUserTable()->checkVerify($username);
                $user_session = new 'Zend'Session'Container('user');
                $user_session->is_admin=$is_admin->is_admin;
                foreach($is_active as $row)
                {
                    $a = $row->is_active;
                }

                $credential->getDbSelect()->where('is_active = TRUE');
                $result = $this->getAuthService()->authenticate();
                switch ($result->getCode()) {
                    case Result::FAILURE_IDENTITY_NOT_FOUND:
                        /** do stuff for nonexistent identity **/
                        if($a == 0)
                        {
                            $this->flashMessenger()->addMessage('Your account could not be verified!
                            Or Wrong Username was entered');
                        }
                        else
                        {
                            $this->flashMessenger()->addMessage('Please check your username !!!');
                        }
                        break;
                    case Result::FAILURE_CREDENTIAL_INVALID:
                        /** do stuff for invalid credential **/
                        $this->flashMessenger()->addMessage('Wrong Password entered!!!');
                        break;
                    case Result::SUCCESS:
                        /** do stuff for successful authentication **/
                        $user_session->username = $request->getPost('username');
                        $redirect_admin = 'admin';
                        $redirect_mem='profile';
                        if($request -> getPost('rememberme') == 1)
                        {
                                $this->getSessionStorage() ->setRememberMe(1);
                                $this ->getAuthService() -> setStorage($this -> getSessionStorage());
                        }
                        $this->getAuthService()->setStorage($this->getSessionStorage());
                        $this->getAuthService()->getStorage()->write($request->getPost('username'));
                        break;
                    case Result::FAILURE_UNCATEGORIZED:
                        $this->flashMessenger()->addMessage('Uncategorized Failure occurred. Please try again later!!!');
                        break;
                    default:
                        /** do stuff for other failure **/
                        $this->flashMessenger()->addMessage('Something unexpected went. Please try again later!!!');
                        break;
                }
            }
        }
        if($is_admin->is_admin=='Y')
        {
          return $this -> redirect() -> toRoute($redirect_admin);
        }
       if($a==NULL)
       {
        $this->flashMessenger()->addMessage('Your account could not be verified!
                            Or Wrong Username was entered');
       }
        if($is_verify->is_verify==0)
        {
            return $this -> redirect()->toUrl('http://marwarishaadicentre.in/profile/edit/'.$is_verify->mem_code);
        }
        else
        {
            return $this -> redirect() -> toRoute('profile');
        }
}

我在zendframework-2中创建了我的网站,并部署在Linux服务器上,但在重定向时它不应该工作。它将在上次操作时停止。例如:-在进行身份验证时,它可以成功进行身份验证,但在重定向时,它将停止。$this->redirect()->toRoute('admin');这段代码不起作用,在整个项目中,任何重定向都不起作用。toRoute('admin')或toUrl('http://marwarishaadicentre.in/admin’)这些功能不起作用。

试试这个,我想你只是没有变量$is_admin

'Zend'Debug'Debug::dump($is_admin); // !!!!!!!!
if($is_admin->is_admin=='Y')
{
    return $this -> redirect() -> toRoute($redirect_admin);
}

我也遇到了同样的问题。我用以下重定向方法解决了这个问题:

 return $this->redirect()->toUrl($redirect_admin);

请确保您分配的url变量在模块名称前面有正斜杠("/"),如下所示。

 $redirect_admin = '/admin';

我希望这对你有用。