1

I pass a query string to SearchController::actionDefault in form of GET parameter q:

/search/?q=...

However I need to define a rule that would automatically initialize this parameter with some value or define another param.

If I'll request mysite.com/showall I need get the same content like in /search/?q=*

This is what I've tried:

'/showall' => '/search/default/index/?r=*',

2
  • You mean, that you need one rule where params will be passed with standard get syntax? Commented Jul 24, 2013 at 13:45
  • @PeterM Yes, just one static rule for one page Commented Jul 25, 2013 at 9:13

2 Answers 2

1

I solved this!

there is possible to set defaultParams in urlManager, and finaly it looks like in application config file:

...
'components' => array(
    ...

    'urlManager' => array(
        ...
        'rules' => array(
            ....
            '/show_all' => array( '/search/default/index', 'defaultParams' => array('show_all'=>'-') ),
            ....
        ),
        ...
    ),
    ...
),
Sign up to request clarification or add additional context in comments.

1 Comment

+1 This is usable in more situations and official documentation doesn't introduce it in any way. Thank you :)
0

The accepted answer also works when you are getting different requests and you need to map it to the same GET param.

For example I want all of these requests:

  • user/pics
  • user/photos
  • user/pictures

to actually generate: user/index?content=photos.

This might be one of a way to go:

'<controller:user>/(<content:photos>|pics|pictures)' => array('<controller>/index', 'defaultParams'=>array('content'=>'photos')),

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.