重写?search =查询到/ search / query和分页

时间:2014-08-05 23:40:58

标签: php .htaccess codeigniter mod-rewrite pagination

我在控制器中的方法可以收到:

  

domain.com/busqueda/anything

这将在我的数据库中搜索“任何内容”并对结果进行分页,因此如果不止一个则需要第三个值:

  

domain.com/busqueda/anything/10

'10'将是偏移量。

使用带有GEt方法的表单将导致:

  

domain.com?busqueda=anything

我的控制器不接受。所以我需要将其重写为:

  

domain.com/busqueda/anything /

并且能够在键入或直接链接时接受偏移值,如:

  

domain.com/busqueda/anything/10

当htaccess到来时我很糟糕。我已经尝试过一些规则但只能使用“偏移”。

1 个答案:

答案 0 :(得分:0)

您可以为表单制作另一种控制器方法,您可以在其中获取GET参数并进行重定向:重定向(' busqueda /'。$ this-> input-> get( ' busqueda'));


如果路由出现问题:

在application / config / routes.php中添加:

$route['busqueda/(:any)/(:num)'] = 'busqueda_controller/busqueda_method/$1/$2';
$route['busqueda/(:any)'] = ''busqueda_controller/busqueda_method/$1';

在你的busqueda_controller / busqueda_method中只需:

$offset = false; //no offset

if(FALSE !== $this->uri->segment(3)) {
    $offset = (int)$this->uri->segment(3); //I've used casting, because I don't know how CI does it. Maybe it's unnecessary here
}
相关问题