2016-09-01 29 views
0

我是codeigniter的新用戶,我遇到此問題, config/config.php中的base_url爲 $config['base_url'] = 'localhost/codeigniter/index.php/stud/';代碼和地址欄中的鏈接網址與預期不同

,我使用,鑑於/ Stud_view.php

echo "<td><a href = '".base_url()."/edit/".$r->roll_no."'>Edit</a></td>";

但在地址欄中則顯示爲http://localhost/codeigniter/index.php/index.php/stud/edit/21

這裏的index.php正在出現兩次。 如果我從地址欄中刪除index.php,那麼它工作正常。 這是怎麼回事?

+1

嘗試'$配置[ 'BASE_URL'] = 'HTTP://本地主機/爲yourprojectname /';'使用配置基本URL http和確保文件和類名只有第一個字母上案件。 – user4419336

+0

您正在使用哪個版本的Codeigniter? – DFriend

+0

鏈接中需要的URL是什麼? – DFriend

回答

1

base_url應該是絕對,包含協議,它不包括index.php

$config['base_url'] = 'http://localhost/codeigniter/ 

你的URL可以被理解爲:

<?php 
    $url = site_url("stud/edit/" . $r->roll_no); 
    echo "<td><a href='" . $url . "'>Edit</a></td>"; 
?> 

最終網址看起來像......

http://localhost/codeigniter/index.php/stud/edit/{roll_no} 

index_page所定義的site_url()功能將包括 「的index.php」配置設置。 base_url()函數將不是包括「index.php」)

參見:codeigniter.com/userguide3/helpers/url_helper.html#site_url

+0

嘿謝謝,我在其他地方也有不同的問題,它在兩個地方都工作得很好 –

-1

從base_url config中刪除網址。 變化:

$config['base_url'] = 'localhost/codeigniter/index.php/stud/'; 

到:

$config['base_url'] = ''; 

,並更改您的網址:

echo "<td><a href = '".site_url()."/edit/".$r->roll_no."'>Edit</a></td>"; 
+0

使用你的方法後;地址更改爲'http:// 127.0.0.1/codeigniter/index.php/edit/23',它又不起作用 –

+2

如果OP使用的codeigniter> = 3.0.0版本,那麼這是一個非常糟糕的建議。根據[文檔](http://www.codeigniter.com/user_guide/installation/upgrade_300.html?highlight=base_url#step-19-make-sure-your-base-url-config-value-is-not-空)「確保你的'base_url'配置值不爲空」。或者,在'config.php'對基站URL的註釋:「警告:你必須設置這個值!」 – DFriend