You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CodeIgniter4如何仅获取GET参数的对应值

CodeIgniter4 获取单个查询参数值的方法

不需要自行拆分处理,CodeIgniter4 提供了直接获取单个查询参数值的方法:

方法一:使用 getVar() 直接获取单个值

$uri = current_url(true);
$id2Value = $uri->getVar('id2');
echo $id2Value; // 输出 val2

方法二:使用 getVars() 获取指定参数的键值对

如果需要一次性获取多个指定参数,也可以用这个方法再提取对应值:

$uri = current_url(true);
$targetParams = $uri->getVars(['only' => ['id2']]);
echo $targetParams['id2']; // 输出 val2

补充说明

getQuery() 方法的设计目的是返回完整或指定部分的查询字符串(比如 id2=val2),而 getVar()/getVars() 才是专门用于提取查询参数键值数据的工具,完全满足你直接获取参数值的需求。

内容的提问来源于stack exchange,提问作者v1n_vampire

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 04:17:02