2013-10-24 38 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然后我们将其路由到该函数。否则,我们将发送别名控制器&检查函数以查看用户是否存在用户名。