Question

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=*',

Était-ce utile?

La solution

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'=>'-') ),
            ....
        ),
        ...
    ),
    ...
),

Autres conseils

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')),
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top