CodeIgniter:URI和表单 [英] CodeIgniter: URIs and Forms

查看:113
本文介绍了CodeIgniter:URI和表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用CodeIgniter实现一个搜索框,但我不知道如何通过搜索参数。我有三个参数:搜索字符串;产品分类;和排序顺序。它们都是可选的。目前,我通过 $ _ POST 将参数发送到临时方法,该方法将参数转发到常规URI表单。这工作正常。我使用的是古怪的URI格式:

  http://site.com/products/search=computer,sort= price,cat = laptop 

有没有人有更好的/更干净的格式的通过东西?
我正在考虑将其作为参数传递给产品的方法,但由于参数是可选的,事情会变得凌乱。我应该把它吸了,只是把 $ _ GET 方法打开?提前感谢!

解决方案

查询字符串



href =http://codeigniter.com/user_guide/general/urls.html =nofollow noreferrer>在CodeIgniter 中启用查询字符串,允许更标准的搜索功能。



Config.php

  $ config ['enable_query_strings'] = FALSE; 

启用后,您可以在应用程式中接受以下内容:

  http://site.com/products/search?term=computer&sort=price&cat=laptop 

这里的好处是,用户会发现很容易编辑URL以快速更改他们的搜索,并且您的搜索使用常见的搜索功能。 / p>

这种方法的缺点是,你违反了CodeIgniter开发团队的一个设计决策。但是,我个人认为,如果查询字符串不用于大部分内容,只有在搜索查询等特殊情况下才能使用。


I'm implementing a search box using CodeIgniter, but I'm not sure about how I should pass the search parameters through. I have three parameters: the search string; product category; and the sort order. They're all optional. Currently, I'm sending the parameters through $_POST to a temporary method, which forwards the parameters to the regular URI form. This works fine. I'm using a weird URI format though:

http://site.com/products/search=computer,sort=price,cat=laptop

Does anyone have a better/cleaner format of passing stuff through? I was thinking of passing it into the products method as arguments, but since the parameters are optional things would get messy. Should I suck it up, and just turn $_GET methods on? Thanks in advance!

解决方案

Query Strings

You can enable query strings in CodeIgniter to allow a more standard search function.

Config.php

$config['enable_query_strings'] = FALSE;

Once enabled, you can accept the following in your app:

http://site.com/products/search?term=computer&sort=price&cat=laptop

The benefit here is that the user will find it easy to edit the URL to make a quick change to their search, and your search uses common search functionality.

The down side of this approach is that you are going against one of the design decisions of the CodeIgniter development team. However, my personal opinion is that this is OK provided that query strings are not used for the bulk of your content, only for special cases such as search queries.

这篇关于CodeIgniter:URI和表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆