[eluser]xwero[/eluser]
I wonder why you need to mix segments with query strings they make it more difficult for the user to create the url.
I would allow users to create urls like these
Code:
// For an XML response
'http://mysite.com/api/categories/orderby/id/sort/desc.xml?accesskey=555555555'
'http://mysite.com/api/categories/.xml?accesskey=555555555'
// For a serialized PHP response
'http://mysite.com/api/categories/orderby/id/sort/desc.php?accesskey=555555555'
// For a JSON object response
'http://mysite.com/api/categories/orderby/id/sort/desc.json?accesskey=555555555'
I would only keep the accesskey in the querystring because it has nothing to do with the data itself.
So the controller method would look like this
Code:
function categories()
{
$format = '.php'; // default output
$valid_formats = array('.php','.xml','.json');
$optional = $this->uri->uri_to_assoc(); // the default segment is 3 so this works on this url
if(count($optional) == 1 && current($optional) == false && in_array(current(array_keys($optional)),$valid_formats))
{
$format = current(array_keys($optional));
$optional = array();
}
elseif(count($optional) >= 1 && in_array(strrchr(end($optional),'.'),$valid_formats))
{
$format = strrchr(end($optional),'.');
$optional[count($optional)-1] = str_replace($format,'',end($optional));
}
// build query with(out) optional limits
// output the desired format
}