0
我擁有類似base_url/Category/productname-254的網址當產品ID在URL中更改時重定向url codeigniter
這裏254是該產品的ID。另外類別是通過在route.php中添加路由,如 $ route ['(:any)/(:any)'] ='controller/index/$ 1/$ 1';
如果我將產品ID從254更改爲產品Id 344,那麼它應該重定向到344產品頁面。
像下面網址:
如果更改是55至58號,然後它被重定向到以下網址 http://www.marketsandmarkets.com/Market-Reports/nanomaterials-58.html
上述網址最後一個數字是產品頁面產品ID 58。
這是從那裏我得到URL我的功能:
function get_report_url($reporttitle,$reportid){
//$title1 = str_replace(array('(', ')'), '',$reporttitle);
$title1 = str_replace(array('(', ')'), '',$reporttitle);
$title1 = str_replace(array(',','?'), "-",$title1);
$title1 = str_replace(array("'", "&", "º","°","ordm;"), "",$title1);
$title=explode(" ",$title1);
//$title=explode(" ",$row['reportTitle']);
$fintitle="";
foreach($title as $words){
$fintitle=$fintitle.$words.'-';
}
$fintitle=$fintitle.$reportid;
$query1 = $this->db->query("SELECT category FROM ur1 WHERE id=".$reportid);
$cat = $query1->row();
$url = base_url()."".$cat->category."/".$fintitle;
//$url = base_url()."index/report/".$cat->category."/".$fintitle;
return $url;
}
控制器去上面的網址:
class Index extends CI_Controller {
function __construct(){
parent::__construct();
}
function report($cat,$rep){
$ttl = explode("-",$this->uri->segment(2));
$reportid = end($ttl);
//echo "reportid ".$reportid;
/*echo "category ".$cat;*/
//exit;
$this->load->model('show_model','',TRUE);
$arr_result = $this->show_model->get_report_details($reportid);
//echo "reportid ".$reportid;
/*print_r($arr_result);
exit;*/
$data['error'] = $arr_result[0];
$data['result'] = $arr_result[1];
$this->load->view('includes/header');
$this->load->view('includes/breadcrumbs');
$this->load->view('pages/reportpage',$data);
$this->load->view('includes/footer');
}
}
route.php
$route['(:any)/(:any)'] = 'index/report/$1/$1';
任何幫助是肯定的iated。 在前提前
請澄清您的具體問題或添加其他詳細信息,以突出顯示您的需要。正如目前所寫,很難確切地說出你在問什麼。請參閱[如何提問](https://stackoverflow.com/help/how-to-ask)頁面以獲得澄清此問題的幫助。有一些代碼會有幫助。 – Tpojka
你有什麼錯誤? – Tpojka
我沒有得到任何錯誤,它只是不重定向..住在同一頁 – SYB