CakePHP log in redirect to requested URL

巧了我就是萌 提交于 2019-12-05 20:26:38
deceze

"According to the cake documentation the authcomponent only preserves this in the session if the user is not coming from an external link."

Read the section again:

The AuthComponent remembers what controller/action pair you were trying to get to before you were asked to authenticate yourself by storing this value in the Session, under the Auth.redirect key. However, if this session value is not set (if you're coming to the login page from an external link, for example), then the user will be redirected to the URL specified in loginRedirect.

It will remember the page you were trying to access, unless you went to the login page directly and hence there's no previous page you came from. If you link to /foo/secret_page and are redirected to the login page though, /foo/secret_page should be remembered in the session.

If you get rid of the $this->Auth->autoRedirect = false and let the AuthComponent do its thing, it should work the way you want.

Otherwise you can read and set the 'Auth.redirect' session key manually to have more control over redirects.

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