Search code examples
lithium

Wildcard lithium routing


I want to route something like this: http://myapp.com/mycontroller/...?x=...

where everything after mycontroller is unknown. I dont know the path and i dont know any of the parameters. After routing the path and parameters should appear as one variable.

// route in routes.php
Router::connect('/mycontroller/*', 'Mycontroller::index');

// the index function of Mycontroller class
public function index($pathWithParameters) {
    print_r($pathWithParameters); // something like: 'hello/world?name=mewel&id=123
}

Is this possible?


Solution

  • Router::connect('/mycontroller/{:args}', 'Mycontroller::index');
    

    then, from your controller, check $this->request->params, and $this->request->query

    NB: you can use func_get_args() in your controller as well. Take a look to default PagesController for an example