数组中 url/paramname/valueparam 的参数数量可变?

发布于 2024-09-09 06:44:32 字数 1025 浏览 2 评论 0原文

基本上我想读取数组中的 url 参数,因此查找参数不依赖于它们在 url 中的位置

我有一个用于搜索的 url controller/action/paramA/valueparamA/paramB/valueparamB 这些参数是可选的:我有直接的 url,其中包含搜索参数,

以便从 url 读取参数,我们必须使用 action(valueparamA, valueparamB) 但对我来说这似乎很僵化 我想按参数名称读取参数,而不是按参数在 url 中的位置读取!

所以我可以有不同的网址,就像

urlA = controller/action?paramA=valueA 
*(or controller/action/paramA/valueA)*
urlB controller/action?paramB=valueB

我可以使用相同的操作一样,就像我们使用带有 $_POST 数组的表单一样(当直接网址参数时,它和 $_GET[} 似乎总是空的) 形式一样,

最好的办法是将所有参数放在一个数组中[paramname=>paramvalue],就像我不想要的 您可以对不同的参数使用不同的操作! :)

我看到的最好的方法是在类似数组的参数上使用 juste :

controller/action/array[paramname=>paramvalue]

(将数组作为 url 参数传递< /a>) 但这似乎使一些基本的事情变得复杂: 只需像每个框架都知道的那样读取正常的 url 参数:)

url?nameparam=valueparam&...

希望有一个解决方案! 我开始非常喜欢 ci 的轻便和快速,但有时(比如扩展模型)它似乎有点“僵化”;)

提前考虑任何想法!

basicly I would like to read url params in an array so finding params don't depend on their place in url

I have a url for seach with controller/action/paramA/valueparamA/paramB/valueparamB
theses params are optional : I have direct url with search params inside

to read params from url we have to use action(valueparamA, valueparamB)
but for me it seems really rigid
I want to read parameters by their name, not by their place in url!

so I can have different urls like

urlA = controller/action?paramA=valueA 
*(or controller/action/paramA/valueA)*
urlB controller/action?paramB=valueB

than I can use with the same action, like we do with a form with $_POST array (it and $_GET[} seems always empty when direct url params)
the best would be to have all parameters in an array[paramname=>paramvalue] like in a form

what I DON'T want is tu use differents actions for different parameters possibles! :)

the best I saw was to use juste on array like parameter :

controller/action/array[paramname=>paramvalue]

(passing arrays as url parameter)
but it seems to complicate something basic :
just read the normal url parameters like every framework knows :) with

url?nameparam=valueparam&...

hope there is a solution !
I begin tor eally like the light and quick of ci but sometimes (like for extending model) it seems a little "rigid" ;)

think in advance for any idea!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最美不过初阳 2024-09-16 06:44:32

是的,URI 类以以下形式提供此功能:

$this->uri->uri_to_assoc(n);

这将返回一个包含所有参数的数组(键和值必须在 URL 中定义)。

完整的详细信息可以在 Codigniter 用户指南中找到:

http://codeigniter.com/user_guide/libraries/ uri.html

Yep the URI class provides this functionality in the form of

$this->uri->uri_to_assoc(n);

This returns an array containing all parameters (keys and values must be defined in the URL).

Full details can be found on the Codigniter Userguide:

http://codeigniter.com/user_guide/libraries/uri.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文