我有这样的链接
http://example.com/search/texas
我希望它路由到控制器search
,URL应该是
http://example.com/schools-in-texas
到目前为止我做了什么
在路线上
$route['search/(:any)'] = "search"; //search is a controller
在搜索控制器上,我texas
使用
$x = $this->uri->segment(2);
我想查询数据库并使用结果来打开一个搜索模板,其中url是搜索项在http://example.com/schools-in-texas
哪里texas
。
我重定向到url,但未从数据库加载数据,因此无法按预期工作。
$url = $this->uri->segment(2);
redirect('schools-in-'.$url, 'refresh');
有人可以提供任何想法如何实现这一目标吗?
试试这个路由
$route['schools-in-(:any)'] = 'search';
这将考虑到Search
控制器时,您的网址就会像http://example.com/schools-in-texas
为了texas
从网址(用于搜索字词)中获取单词,您现在可以使用
$state_name = substr($this->uri->segment(1), strrpos($this->uri->segment(1), '-') + 1);
现在$state_name
将输出,texas
就像您输入URL http://example.com/schools-in-texas
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句