用codeigniter写我的url:
http://myurl.com/username
如果输出为:
1) http://myurl.com/username/about_us
2) http://myurl.com/username/profile
3) http://myurl.com/username/account
如何在输出中找到username
?我对
做了一些研究http://www.codeigniter.com/userguide2/general/routing.html但仍然没有得到正确的解决方案。
有谁能帮忙吗?提前感谢!
好的…我假设您使用的是"User"控制器,您的代码和然后每个视图的函数如下
class User extends CI_Controller
{
function __construct()
{
parent:: __construct();
}
public function about($username)
{
//code here
//load view
}
public function profile($username)
{
//code here
//load view
}
public function account($username)
{
//code here
//load view
}
}
然后进入你的config/routes.php文件,添加这些路由
$route['(:any)/about_us'] = "user/about/$1";
$route['(:any)/profile'] = "user/profile/$1";
$route['(:any)/account'] = "user/account/$1";
有了这个,你可以很容易地从任何页面函数中使用$username
在config/routes.php中试试
$route[':any'] = "controller/function";
和aboutus及其他
$route[':any/aboutus'] = "controller/aboutus";
在你的控制器
$this->uri->segment(1);
获取用户名