0

i´m a bit confused about using optional parameters and phpdocs. I got the following @url statement:

@url GET /pruefvorschrift/:typs

now want to set :typs as optional so i do

function getpruefvorschrift ($typs=null) {...

this isn´t working, value for :typs is never available in $typs. If i change the above @ url rout to use other word e.g. :id it works?

I don´t understand it could anyone help?

For completeness: I have many functions in this file

get /device.json/{id}

get /device/pruefvorschrift/:typs.json

get /device/serial.json/{serial}

get /device/:id/merkmale.json

Hope one could help,

thx Inge

Inge
  • 427
  • 7
  • 20

1 Answers1

0

The parameter name is not the problem here!

Using optional parameter as part of the URL is strongly discouraged

By setting a default value for $typs you are making it optional

Which means we need to create two routes for the same api method

GET /device/pruefvorschrift/{typs}

And

GET /device/pruefvorschrift

By default restler 3 does not do it, where as restler 2 does it by default

You can add the following to the phpdoc comment to change that behaviour

/**
* @smart-auto-routing false
*/
function getpruefvorschrift ($typs=null) {

But keep in mind this may stand in the way of another route, read further at http://restler3.luracast.com/examples/_006_routing/readme.html and https://github.com/Luracast/Restler/issues/10

Arul Kumaran
  • 983
  • 7
  • 23
  • One more question. If you say optional parameters are strongly discouraged how would you solve it? Thx for your hint – Inge Mar 20 '13 at 06:22
  • optional parameter? use a query string, required param of simple type (strings, numbers etc) ? put it in the url, complex types (array or object) if using http GET or DELETE only way is query string, otherwise send it through the BODY – Arul Kumaran Mar 20 '13 at 08:23