質問

As like facebook(facebook.com/userurl) I like to use domain.com/username in codeigniter. Here username is unique one. I want to create every register user have his/her own url(path). Can anyone help regarding this?

役に立ちましたか?

解決

That's not URL. Understand the Concept. You having some Basic problem. Use that id as Parameter(GET method).

See this Image: enter image description here

Get something? For more...

As your point use

$this->uri->segment(2);

Link

As your question,

localhost/codeigniter/ripon

this is your URL. So, in your default Controller, way 1:

public function index($user)
{
    echo "User is ".$user;
}

way 2:

public function index()
{
    $user = $this->uri->segment(2);
    echo "User is ".$user;
}

他のヒント

Add the following code in routes.php file in configs before any custom routes

 $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";

Please Refer these question - How would i create a vanity url in codeigniter

In brief, we check whether the controller and function name exist in the URL..IF it does then we route it to that function..Else we will send to aliases controller & check function to see if the user exist with that username.

I get the desire solution form http://www.aamra24.com/how-to-use-domain-then-username-in-codeigniter/

You need to add following code to application/config/routes.php

$route['(.*)'] = "welcome/index/$1";
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top