문제

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