0

I have a query interface that allows for say 4 possible fields to query, name, birthyear, astrological sign, and birthstate. The user can provide a value for any one of these fields. I am using AngularJS (immaterial here) and YiiFramework (material).

I have seen answers to questions similar to this, but for the most part, people end up using querystring parameters. I can account for that in my urlManager, but would prefer to do this in the 'right' RESTful way. I have seen examples showing how to do this as:

/myservice/index.php/names/jones?birthyears=&signs=leo&birthstates=maine - meaning they did not supply birthyear

My thought to do this completely with paths skipping blank values. Is this a reasonable approach:

/myservice/index.php/api/modelname/names/jones/birthyears//signs/leo/birthstates/maine

if so, then i am struggling with the urlManager pattern

array('api/find', 'pattern'=>'api/<model:\w+>/names/<names:(|\w+)>/birthyears/<birthyears:(|\d{4})>/signs/<signs:(|\w+)>/birthstates/<birthstates:(|\w+)>', 'verb'=>'GET')

when i pass the above path to this i do not get the expected resolution. I am sure there is a better way to deal with this

Cord
  • 317
  • 2
  • 10

1 Answers1

0

I tested it here and it worked.

How are you setting the parameters of your urlManager?

The urlFormat property is set to 'path'?

'urlManager' => array(
    'urlFormat' => 'path', // You have to leave it like that.
 //   'urlSuffix' => '.html',
    'showScriptName' => false,
    'caseSensitive' => true,
    'useStrictParsing' => true,
    'rules' => array(
       array('api/find', 'pattern'=>'<model:\w+>/names/<names:(|\w+)>/birthyears/<birthyears:(|\d{4})>/signs/<signs:(|\w+)>/birthstates/<birthstates:(|\w+)>', 'verb'=>'GET'),
       // Other rules here
    ),
),
FabianoLothor
  • 2,752
  • 4
  • 25
  • 39
  • Thank you, i am trying this again now with your additional urlManager parameters in there. I had it set to urlFormat path, but not the other parameters. I am getting an error resolving the controller: "The system is unable to find the requested action" – Cord Oct 24 '12 at 23:01
  • I ended up removing the separators and was able to get the system working. I gather this is not restful, but my path is now something like: /jones//leo/maine - which is matched by //// and now putting back the groupings and that works too. so, thanks for your help. – Cord Oct 24 '12 at 23:12
  • Glad to have helped, needing just talk! – FabianoLothor Oct 25 '12 at 11:23