Handling pretty URLs with single pages

Permalink
Hi All,

I'm looking for some tips of how to use querystring variables to power my single page, but have those variables "pretty".

Currently I have a single page for job listings, which reads from an external data source. This links to job detail pages, all powered from the one single page.

I have it setup so that example.com/jobs/?jobid=123 loads a single job listing. I would like this to be example.com/jobs/123/ or example.com/jobs/123-web-developer/

Basically looking for a way to bind these URL patterns to my single page. Is anyone able to advise on this please?

Sadu
 
JohntheFish replied on at Permalink Best Answer Reply
JohntheFish
After the path to the single page is matched, further path parts will get matched to actions (functions in the single page controller or single pages below it). Any remaining path parts can become parameters to the function, provided the function declares parameters to accept them.

So if you have a single page at /mysite/jobs/

By default, function view() in the controller for jobs will be called.

If you now have a path
/mysite/jobs/category/subcategory/,
and view has a couple of parameters:
function view($cat, $subcat);

Then this path will also map to view(), but only if view() has enough parameters to accept the additional parts of the path and only if you don't also have an action function or page /mysite/jobs/category/ which the C5 dispatcher will give precedence to.

You can't just pull them out of the arguments array because the C5 dispatcher decides based on declared parameters. On the other hand, you can declare a long list of parameters just in case, to grab whatever path may be thrown at the function in your jobs single page controller:
function view($p0, $p1, $p2,..... $p9);
  $args = func_get_args();
Sadu replied on at Permalink Reply
Sadu
Perfect. Too easy.

thanks for your help.