Php 如何在url codeigniter中显示选中的筛选器变量值

Php 如何在url codeigniter中显示选中的筛选器变量值,php,codeigniter,codeigniter-3,Php,Codeigniter,Codeigniter 3,我是CodeIgniter和PHP的基本用户。我有一些带有过滤器的产品页面。如何创建如下URL链接: BASE URL/Controller/method/params class Products extends CI_Controller { public function lookupProductById($product_id = null) { // whatever you need to do (like querying the database to

我是CodeIgniter和PHP的基本用户。我有一些带有过滤器的产品页面。如何创建如下URL链接:

BASE URL/Controller/method/params
class Products extends CI_Controller {
   public function lookupProductById($product_id = null)
   {
      // whatever you need to do (like querying the database to fetch info for the product with a certain product ID) goes here
     // for instance, start by checking that the product ID was passed in the URI
     if  ($product_id == null)
     {
        // handle exception
     }

     else
     {
        // query the database and fetch info for the product whose ID is $product_id
     }

   }

}
http://somepage.pl/products?color=red

我知道我可以在更改配置行时执行上述url:

$config['enable\u query\u strings']=FALSE为真


但是我只想使用这个选项一个控制器和一个函数

您的最佳选择是依赖codeigniter的本地URI重写

默认情况下,(我这里不讨论自定义路由,但如果您了解它们,您可能会这样做)Codeigniter提供的URL如下所示:

BASE URL/Controller/method/params
class Products extends CI_Controller {
   public function lookupProductById($product_id = null)
   {
      // whatever you need to do (like querying the database to fetch info for the product with a certain product ID) goes here
     // for instance, start by checking that the product ID was passed in the URI
     if  ($product_id == null)
     {
        // handle exception
     }

     else
     {
        // query the database and fetch info for the product whose ID is $product_id
     }

   }

}
基本url将是您在配置中定义的内容,通常是站点的基本域,如
example.com

由于CI是基于MVC体系结构构建的,所以您的所有功能必须在一个或多个控制器中的不同方法上“运行”。因此,例如,您可能有一个名为
products
的控制器,在该控制器中您可能有一个名为
lookupProductById
的方法(为了简单起见:函数),该方法将接受一个参数(
$product\u id
)。看起来是这样的:

BASE URL/Controller/method/params
class Products extends CI_Controller {
   public function lookupProductById($product_id = null)
   {
      // whatever you need to do (like querying the database to fetch info for the product with a certain product ID) goes here
     // for instance, start by checking that the product ID was passed in the URI
     if  ($product_id == null)
     {
        // handle exception
     }

     else
     {
        // query the database and fetch info for the product whose ID is $product_id
     }

   }

}
因此,当访问
example.com/products/lookupProductById/8
时,您将能够获取与产品ID 8相关的信息

您可能需要阅读(介绍性章节和教程将引导您(非常)基本地了解MVC框架如何运行、控制器、模型和视图如何交互以产生结果等),以便更好地了解您所了解的内容:)