Curlmanager rules problem

Hi,

I’m trying to add a rule to the UrlManager to manage a situation like this:

there is a search engine where the user can type what he wants.

When the form is submitted, I produce such a URL:

http://mysite/search/<the word typed by the user>

So I want to “redirect” any URL pointing to the “search” controller to the same action and use the word typed by the user as a parameter for the action. If I don’t get it as a param, it’s not a problem because I can get it in $_POST.

The big problem is to redirect everything to the same action.

Thanks a lot.

UrlManager rule:


'rules' => array(

   'search/<query:.*>' => 'example/search',

),

Example controller:




class ExampleController extends CController

{


   public function actionSearch($query)

   {

      // if uri is /search/test then $query == 'test'

   }


}



If $query is optional, means if /search alone (without a query) should be accessible as well, then you can do:


'rules' => array(

   'search/<query:.*>' => 'example/search',

   'search' => 'example/search',

),




class ExampleController extends CController

{


   public function actionSearch($query = null)

   {

      // $query == null if uri is /search

   }


}



Thanks a lot. Perfect.

I had almost found the solution, except I had forgotten to put the specific rules BEFORE the default ones:

‘<controller:\w+>/<id:\d+>’=>’<controller>/view’,

‘<controller:\w+>/<action:\w+>/<id:\d+>’=>’<controller>/<action>’,

‘<controller:\w+>/<action:\w+>’=>’<controller>/<action>’,