我有一个与将一个操作重定向到实时站点上的另一个操作相关的问题。(http://marwarishaadicentre.in/)我在身份验证操作中发布了此代码中的身份验证控制器代码可以成功进行身份验证,但不能在管理员或配置文件路由上重定向。
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');
}
}我在zend framework-2中创建了我的站点,并将其部署在Linux Server上,但在重定向时它应该无法工作。它将在上一次操作时停止。例如:-在身份验证时,它可以成功地进行身份验证,但在重定向时将停止。$ this -> redirect ()->toRoute('admin');此代码不起作用,并且在整个项目中任何地方重定向都不起作用。toRoute('admin')或toUrl('http://marwarishaadicentre.in/admin')这些函数不起作用。
发布于 2013-08-09 00:24:03
试试这个,我想你只是没有变量$is_admin
\Zend\Debug\Debug::dump($is_admin); // !!!!!!!!
if($is_admin->is_admin=='Y')
{
return $this -> redirect() -> toRoute($redirect_admin);
}发布于 2013-10-09 12:36:38
我也为同样的问题而苦苦挣扎。我已经通过以下重定向方法解决了这个问题:
return $this->redirect()->toUrl($redirect_admin);请确保分配给您的url变量在模块名称前面有正斜杠("/"),如下所示。
$redirect_admin = '/admin';我希望这对你有用。
https://stackoverflow.com/questions/18095926
复制相似问题