Yii framework: Controller/Action url amp; parameters(Yii 框架:控制器/动作 url amp;参数)
问题描述
在我的应用程序中,我有 ApiController 和 actionUsers,所以在 YII 中,路径变为 api/users.现在为了获取某些用户信息,我使用以下路径 api/users/id/10 其中 10 是用户 ID,路径的 id 部分基本上是一个 GET参数(api/users?id=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).
有没有办法在没有路径的 id 部分的情况下做同样的事情,即我希望我的路径看起来像 api/users/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?
谢谢!
推荐答案
您将需要在 urlManager 组件中放入规则模式:
You're going to need to put in rule patterns in the urlManager component:
Yii 框架文档:url
您的配置应如下所示:
array(
......
'components'=>array(
......
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'api/users/<id>'=>'api/users',
),
),
),
);
然后您可以通过以下方式获取值:
You can then get the value by:
$id = Yii::app()->getRequest()->getQuery('id');
这篇关于Yii 框架:控制器/动作 url &参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Yii 框架:控制器/动作 url &参数
基础教程推荐
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何替换eregi() 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
