0
votes

In the Yii application i am creating i have a search functionality. In this any user(authenticated and guest) can see the searchbox. but when i click the search button only logged in user can see the result. else it will be redirected to login screen . once they login they can see the result.

So I have written accessrule like this

return array(
        array('allow',
            'actions'=>array('search'),
            'users'=>array('@')
        ),

My doubt is when it is coming to the search action there are 2 parameters(POST)(my search keywords). when it goes to loginurl and come back after my successful login to same action How can i get these keywords back ? Is there any direct yii method other than to use session ?

Please help

2

2 Answers

1
votes

First I would suggest making your search form to use GET, not POST, of course this will depend on use cases and requirements, but search forms should use GET to make them more usable & accessible. This should also fix your problem because then Yii will return to the search results URL after login (depending on the code, might not always work).

If you have to use POST then the only way I can see is to make a filter method which will save the keywords to session.

0
votes

I would have done so:

  1. set allow for guest 'users'=>array('*')
  2. In search action if user is guest store search keywords in session, redirect user to login form, and after returned check method if not POST and in session stored keywords - get search keywords from session and searching.