我在控制器内的方法可以收到以下信息:
domain.com/busqueda/任何东西
它将在我的数据库中搜索“任何内容”并分页结果,因此,如果不止一个,则需要第三个值:
domain.com/busqueda/anything/10
“ 10”将是偏移量。
将表格与GEt方法一起使用将导致:
domain.com?busqueda=任何东西
我的控制器不接受。所以我需要将其重写为:
domain.com/busqueda/anything/
并且在键入或直接链接时也能够接受偏移值,例如:
domain.com/busqueda/anything/10
htaccess来的时候我很不好。我尝试了一些规则,但没有“补偿”。
您可以为表单创建另一个控制器方法,在该方法中,您将获取GET参数并进行重定向:redirect('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
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句