Yii 框架:控制器/操作 url &参数
在我的应用程序中,我有 ApiController
和 actionUsers
,因此在 YII 中路径变为 api/users
。现在为了获取某些用户信息,我使用以下路径 api/users/id/10,其中 10 是用户 ID,路径的 id 部分基本上是 GET参数(api/users?id=10
)。
有没有办法在路径中没有 id
部分的情况下执行相同的操作,即我希望我的路径看起来像 api/users/10
?
谢谢你!
In my application , I have ApiController
with actionUsers
, So in YII the path becomes api/users
. Now in order to get certain users info , I use the following path api/users/id/10
where 10 is the userID and id
part of the path is basically a GET parameter (api/users?id=10
).
Is there any way to do the same thing without id
part of the path, i.e. I want my path to look like api/users/10
?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要在 urlManager 组件中放入规则模式:
Yii 框架文档: url
您的配置应如下所示:
然后您可以通过以下方式获取值:
You're going to need to put in rule patterns in the urlManager component:
Yii Framework Documentation: url
Your config should look something like this:
You can then get the value by:
试试这个......
Try This......
除了@shiki的回答之外,你还可以这样做
并采取行动
in addition to @shiki's answer you can also do this
and in action