In my program, I use this code to show information with users' operation:
public function infoShowWithRedirect($msg, $redirectRouteName = 'homepage', $waitTime = 3, $msgType = "success") {
switch ($msgType) {
case 'success':
$this->flashSession->success($msg);
break;
case 'error':
$this->flashSession->error($msg);
break;
default:
$this->flashSession->notice($msg);
break;
}
return $this->response->redirect(array(
'for' => 'user_notice',
'routeName' => $redirectRouteName,
'waitTime' => $waitTime
));
}
And in my controller base, I use previous code this way:
// Get the current identity
$identity = $this->auth->getIdentity();
// If user is not login then redirect the user to login page
if (!is_array($identity)) {
echo 'execute';
return $this->helper->infoShowWithRedirect(
$this->lang->_('has_no_privilege_login'),
'user_login',
2,
'error'
);
}
But I found that it echod "execute" but not redirect to user_login route, so I modify the infoShowWithRedirect() function:
$this->response->redirect(array(
'for' => 'user_notice',
'routeName' => $redirectRouteName,
'waitTime' => $waitTime
));
$this->view->disable();
return false;
And now it works, Why can't I use direct return redirect ?
B.T.W.
$this->response->redirect(array(
'for' => 'user_notice',
'routeName' => $redirectRouteName,
'waitTime' => $waitTime
));
$this->view->disable();
return ;
Is also not working!