Php 在url中更改产品id时重定向url codeigniter
我的url类似于base\u url/Category/productname-254 这里254是该产品的Id 此外,还通过在route.php中添加路由(如 $route['(:any)/(:any)]='controller/index/$1/$1' 如果我将产品Id从254更改为产品Id 344,那么它应该重定向到344产品页面 如以下网址: 若您将上面URL中的最后一个号码55改为58,那个么它将重定向到下面的URL 这是产品Id 58的产品页面 这是我从中获取URL的函数:Php 在url中更改产品id时重定向url codeigniter,php,.htaccess,codeigniter,url-redirection,Php,.htaccess,Codeigniter,Url Redirection,我的url类似于base\u url/Category/productname-254 这里254是该产品的Id 此外,还通过在route.php中添加路由(如 $route['(:any)/(:any)]='controller/index/$1/$1' 如果我将产品Id从254更改为产品Id 344,那么它应该重定向到344产品页面 如以下网址: 若您将上面URL中的最后一个号码55改为58,那个么它将重定向到下面的URL 这是产品Id 58的产品页面 这是我从中获取URL的函数: fu
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;
}
要转到以上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';
感谢您的帮助。
提前感谢请澄清您的具体问题或添加其他详细信息,以突出显示您所需的内容。正如目前所写的,很难准确地说出你在问什么。请参阅页面以获取澄清此问题的帮助。有一些代码会很有帮助。你得到了什么错误?我没有得到任何错误,只是没有重定向。。停留在同一页上,看不到视图、控制器、路由代码,这很难说。再次编辑问题。。。带有控制器和路由。
//go to application->config->routes.php
$route['404_override'] = 'Category'; //override error page with category controller
class Category extends MY_Controller {
function index($product_id=''){
//get product data using product id and load data on view
}
}