2012-01-30 200 views
0

我想將我的視圖頁面鏈接到另一個控制器。codeigniter路徑問題

我test_view.php頁

//this page address is base_url/controller1/function1 
<a href='controller1/function2'> test </a> 

如果我點擊,頁面地址爲base_url/controller1/function1/controller1/function2這不是我的願望。

我控制器

//the first function1 is to show my test_view page 
    function function1(){ 
     $this->load->view('test_view'); 
    } 

    //I can't get to this function2 with the link I used 
    function function2(){ 
     $this->load->view('funny'); 
    } 

任何人都可以幫我這個?非常感謝。

+0

感謝。 +1全部。 – FlyingCat 2012-01-30 16:32:08

回答

2

當然 - 你只需要告訴CodeIgniter的顯示路徑:

<a href="<?php echo site_url("controller1/function2");?>"> 

有一件事:這顯示了您的網站的絕對路徑在您的配置中定義,而不是相對路徑。

我更喜歡相對路徑,所以我喜歡創建一個名爲site_path的通用函數來執行沒有絕對URL的相同事情。我把它給我的普遍加載的圖書館之一,它看起來是這樣的:

function site_path($url) { 
    return "/$url"; 
} 

這樣做的好處是,如果我最初開發網站的子目錄,我可以設置SITE_PATH到return "/subdirectory/$url",然後就我啓動後刪除子目錄。

2

它鏈接到一個相對URL,你需要開始用「/」使用Web根

<a href='/controller1/function2'> test </a> 
2

您可以在test_view.php頁面都使用下面的代碼,
<a href='<?php echo base_url();?>controller1/function2'> test </a>