2013-10-24 80 views

回答

0

這不是URL。理解概念。你有一些基本問題。使用該ID作爲參數(GET方法)。

看到這個圖片: enter image description here

得到的東西?對於more...

隨着你點使用

$this->uri->segment(2); 

Link

至於你的問題,

localhost/codeigniter/ripon 

這是你的URL。因此,在默認的控制器, 方式1:

public function index($user) 
{ 
    echo "User is ".$user; 
} 

方式2:

public function index() 
{ 
    $user = $this->uri->segment(2); 
    echo "User is ".$user; 
} 
+0

這裏的「你好」是控制器的名字和「你」是一個函數名。我不想給它在URL中,我只想給用戶名作爲參數 –

+0

沒有必要。看到這個,http://ellislab.com/codeigniter/user-guide/libraries/uri.html – KarSho

+0

@KarSho他在說什麼是關於虛榮網址.. –

0

任何定製路由之前添加在CONFIGS在routes.php文件文件下面的代碼

$handle = opendir(APPPATH."/controllers"); 
while (false !== ($file = readdir($handle))) { 
if(is_dir(APPPATH."/controllers/".$file)){ 
    $route[$file] = $file; 
    $route[$file."/(.*)"] = $file."/$1"; 
} 
} 

/*Your custom routes here*/ 

/*Wrap up, anything that isnt accounted for pushes to the alias check*/ 

$route['([a-z\-_\/]+)'] = "aliases/check/$1"; 

請參考這些問題 - How would i create a vanity url in codeigniter

簡而言之,我們檢查控制器和函數名是否存在於URL中.IF然後我們將其路由到該函數。否則,我們將發送別名控制器&檢查函數以查看用戶是否存在用戶名。