亲爱的大家,我是 codeigniter 的菜鸟,
我想寻求建议,了解如何创建一个搜索表单,该表单的网址如下:
http://domain/class/index/searchvar1/searcvar1val/searchvar2/searchvar2val
表格就像这样
<form action="http://domain/class/index">
<input name="searchvar1" value="searchvar1val">
<input name="searchvar2" value="searchvar2val">
<input type="submit">
</form>
最佳实践是什么?
我已经用 Google 搜索过,包括 stackoverflow 帖子,但仍然找不到任何解决方案。
谢谢:)
~这就是我的第一篇文章
更新::
我想强调,我的目标是处理搜索变量来自 uri 字符串(上面),而不是来自帖子变量;所以我认为将表单搜索设置为 POST 不是一个选项? :)
更新 (2)
我不认为这可以在 codeigniter 中开箱即用,我正在考虑使用 jQuery 将表单 vars/vals 客户端处理为 URI 格式的表单操作。 完成后将在此处发布更新。
最佳答案
看看 user_guide :
$this->uri->assoc_to_uri()
Takes an associative array as input and generates a URI string from it. The array keys will be included in the string. Example:
$array = array('product' => 'shoes', 'size' => 'large', 'color' => 'red');
$str = $this->uri->assoc_to_uri($array);
// Produces: product/shoes/size/large/color/red
我想如果你的表格是这样的:
<form action="http://domain/class/index/search">
<input name="product" value="shoes">
<input name="size" value="large">
<input name="color" value="red">
<input type="submit">
</form>
然后在搜索 Controller 中的某个位置执行此操作 $this->uri->assoc_to_uri($data);
恕我直言,将产生product/shoes/size/large/color/red
关于php - 如何使用 codeigniter uri 格式创建搜索表单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5815171/