Search code examples
restler

Reserved word in restler 3?


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


Solution

  • 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