CodeIgniter 設定個人首頁

這個是使用CodeIgniter的 URI 路由 以及 URI 类 來達成依不同使用者有自己的首頁。

設定

假設網址為:http://www.shian.tw/user/shian

修改 application/config/routes.php

1
2
//將任何的名稱的 function 都重導至自定義的 index
$route['user/<strong>:any'</strong>] = "user/index";

增加 application/controllers/user.php

1
2
3
4
5
6
7
8
9
10
11
12
class User extends Controller { 
 
    function User()
    {
        parent::Controller();
    }
    function index()
    {
        // 取得網址上分段的資料
        echo $this->uri->segment(2);
    }
}

參考資料

Related Posts with Thumbnails

相關文章