我正在使用笨的一个项目,我的类别URL-S是:笨 - 与名称替换类ID在URL
但我想要的路线看起来像
http://localhost/SabLiveNew/category/NameOfCategory
任何人都可以帮助我吗?
谢谢!
我正在使用笨的一个项目,我的类别URL-S是:笨 - 与名称替换类ID在URL
但我想要的路线看起来像
http://localhost/SabLiveNew/category/NameOfCategory
任何人都可以帮助我吗?
谢谢!
我不这么认为,所以我们有办法在运行时将数字转换为文本。但是您可以按照您的要求进行归档。
例:
URL
http://localhost/SabLiveNew/category/NameOfCategory
在控制器
public function category($getCategory)
{
// set 01
echo "Category is : ".$getCategory;
// Set 02
if ($getCategory== 'xyz') {
echo "this is xyz Category ";
} else {
echo "This is not xyz category ";
}
// Set 03
switch ($getCategory)
{
case 'xyz':
$category = "this is xyz Category";
break;
case 'abc':
$category = "this is abc Category";
break;
case 'pqr':
$category = "this is pqr Category";
break;
default:
$category = "is not any matched category";
break;
}
echo $category;
}
在第一抓URL的最后一个索引
$record_num = end($this->uri->segment_array());
or
$last = $this->uri->total_segments();
$category = $this->uri->segment($last);
在控制器功能,其中调用这个类获取功能获取类别名称
public function get_category($category){
$this->db->where('category_id',$category);
return $this->db->get('categories')->result_array();
}
:0
现在从数据库表中的模型get_category功能得到类别名称,在控制器
$this->model_name->get_category($category);
像下面。
$category_info=$this->model_name->get_category($category);
$category_name=$category_info[0]['category_name'];
现在创建重定向url;
$url=http://localhost/SabLiveNew/category/$category_name;
我觉得http://localhost/SabLiveNew/是你的基地址,以便尝试这种
$url=base_url().'/category/'.$category_name;
终于重定向
redirect($url);
感谢