2017-05-30 174 views
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产品页面。

像下面网址:

http://www.marketsandmarkets.com/Market-Reports/cardiac-monitoring-advanced-technologies-and-global-market-55.html

如果更改是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。 在前提前

+0

请澄清您的具体问题或添加其他详细信息,以突出显示您的需要。正如目前所写,很难确切地说出你在问什么。请参阅[如何提问](https://stackoverflow.com/help/how-to-ask)页面以获得澄清此问题的帮助。有一些代码会有帮助。 – Tpojka

+0

你有什么错误? – Tpojka

+0

我没有得到任何错误,它只是不重定向..住在同一页 – SYB

回答

0
//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 
    } 
}