Home  >  Q&A  >  body text

php - restful 重写update action 在重写完后访问域名/v1/product/ID 的时候方法里怎么获取到ID呢?

Yii2 restful 重写update action 那么问题来了,在重写完后访问api.xxxx.com/v1/product/ID 的时候 方法里怎么获取到ID呢?

迷茫迷茫2683 days ago369

reply all(2)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-16 13:03:35

    In yii2, if your function parameter is ($id), then it will find the value of the passed parameter as id. If you do not pass it, an error will be reported

    That is to say, whatever the parameters of your function are written, the $ sign will be removed to find that parameter, and it must be passed.

    If you don’t want to pass parameters, write formal parameters.

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-16 13:03:35

    Yii::$app->request->get('uid')

    This is how you get it too. It hasn’t changed
    I think you passed the uid directly as a parameter. You just need to use $uid directly.
    The description you submitted is because you did not bring $uid

    It is recommended that you change actionUpdate($uid) to actionUpdate($id), so that you can press your ajax request again

    reply
    0
  • Cancelreply