Codeigniter - 使用在URL中输入的用户名搜索个人资料

时间:2013-02-19 05:51:54

标签: codeigniter codeigniter-url tankauth codeigniter-routing

我正在使用Codeigniter和Tank Auth,我正在使用Ubuntu OS。当我使用我的IP访问我的项目时,它就像:

http://192.168.1.10/project/auth/login

我必须实现使用URL搜索配置文件的功能。假设我输入

http://192.168.1.10/project/vishmay

然后它应该显示我的个人资料。谁能告诉我怎么做?

我已尝试在我的routes.php中执行此操作

$route['default_controller'] = "welcome";
$route['auth/login'] = 'auth/login';
$route['auth/register'] = 'auth/register';
$route['auth/logout'] = 'auth/logout';
$route['welcome/profile'] = 'welcome/profile';
$route[':any'] = 'auth/index/$1';

并在auth.php控制器中创建了index(),如

 function index() {
        $username=$this->uri->segment(1);
        $data['result']=$this->users->get_profile_pic1($username);   
        if ($message = $this->session->flashdata('message')) {
            $data['reg_success'] = "You have been registered successfully.";
            $reg_success = 1;
            redirect('/auth/register', $data);
        } else {
            redirect('/auth/login/');
        }
    }

1 个答案:

答案 0 :(得分:2)

你应该改变:

$route[':any'] = 'auth/index/$1';

$route['(:any)'] = 'auth/index/$1';

使$1可以正确获取分段值。

你可以试试这段代码:

试试这个:

function index($username = '') {
    $data['result']=$this->users->get_profile_pic1($username);   
    if ($message = $this->session->flashdata('message')) {
        $data['reg_success'] = "You have been registered successfully.";
        $reg_success = 1;
        redirect('/auth/register', $data);
    } else {
        redirect('/auth/login/');
    }
}
相关问题