Codeigniter路由网址

时间:2017-07-13 09:27:40

标签: codeigniter

我检查了类似的问题,但那些似乎没有帮助。

我有一个网站,基本网址为:(http://localhost/myproject)。我将使其成为SAAS,由注册用户访问,每个用户将拥有自己的域,如:(http://localhost/myproject/user1)等。当用户注册时,系统将为每个用户生成具有相同域的数据库,因此当每个用户访问他自己的域名,它也将连接到他的数据库。问题是当他键入自己的doamin并在系统中设置所有URL时,如何控制每个用户的路由。我尝试了很多,但没有找到解决方案。请帮忙。提前谢谢。

1 个答案:

答案 0 :(得分:0)

看起来您正在尝试使用用户名创建虚荣网址 尝试重新映射控制器

控制器

    class User extends CI_Controller {
    public function _remap($method, $params = array())
    {
        if (method_exists(__CLASS__, $method)) {
            $this->$method($params);
        } else {
            array_unshift($params, $method);
            $this->user_detail($params);
        }
    }

    public function user_detail($params) {
        $username = $params[0];
        echo 'username: ' . $username;
    }

    public function another_func() {
        echo "another function body!";
    }
}

您可以在此处阅读:How to route cutom URL with to custom controller in CodeIgniter?

  

虽然这会给你这样的东西   http://www.localhost/myproject/user/user_detail/john => '用户名:   约翰'

尝试更新您的路线,例如routes.php

$route['(:any)'] = "user/user_detail/$1";