Welcome Guest, Not a member yet? Register   Sign In
Controller Method file extensions? (.xml or .php)
#3

[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
}


Messages In This Thread
Controller Method file extensions? (.xml or .php) - by El Forum - 04-23-2009, 10:35 AM
Controller Method file extensions? (.xml or .php) - by El Forum - 04-23-2009, 09:35 PM
Controller Method file extensions? (.xml or .php) - by El Forum - 04-24-2009, 01:08 AM
Controller Method file extensions? (.xml or .php) - by El Forum - 04-24-2009, 06:57 AM
Controller Method file extensions? (.xml or .php) - by El Forum - 04-24-2009, 07:21 AM
Controller Method file extensions? (.xml or .php) - by El Forum - 04-24-2009, 07:30 AM
Controller Method file extensions? (.xml or .php) - by El Forum - 04-24-2009, 07:55 AM
Controller Method file extensions? (.xml or .php) - by El Forum - 04-24-2009, 08:26 AM
Controller Method file extensions? (.xml or .php) - by El Forum - 04-24-2009, 08:30 AM
Controller Method file extensions? (.xml or .php) - by El Forum - 04-24-2009, 08:48 AM
Controller Method file extensions? (.xml or .php) - by El Forum - 04-24-2009, 08:52 AM
Controller Method file extensions? (.xml or .php) - by El Forum - 04-24-2009, 08:56 AM
Controller Method file extensions? (.xml or .php) - by El Forum - 04-24-2009, 09:12 AM
Controller Method file extensions? (.xml or .php) - by El Forum - 04-24-2009, 09:14 AM
Controller Method file extensions? (.xml or .php) - by El Forum - 04-24-2009, 09:15 AM
Controller Method file extensions? (.xml or .php) - by El Forum - 04-24-2009, 09:22 AM
Controller Method file extensions? (.xml or .php) - by El Forum - 04-24-2009, 10:40 AM



Theme © iAndrew 2016 - Forum software by © MyBB