Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在CodeIgniter中重新映射URL_Php_Codeigniter - Fatal编程技术网

Php 如何在CodeIgniter中重新映射URL

Php 如何在CodeIgniter中重新映射URL,php,codeigniter,Php,Codeigniter,我需要像CodeIgniter中的facebook一样重定向我的URL 例如:假设我们给出'example.com/username',那么它将显示用户配置文件信息。 但是我的控制器是'example.com/index/username'。这里用户名是参数。 这是我的控制器 class Index extends CI_Controller { public function __construct() { parent::__construct();

我需要像CodeIgniter中的facebook一样重定向我的URL

例如:假设我们给出'example.com/username',那么它将显示用户配置文件信息。 但是我的控制器是'example.com/index/username'。这里用户名是参数。 这是我的控制器

class Index extends CI_Controller {
public function __construct() {
           parent::__construct();

        }

public function index($username=NULL) {

     $this->load->view('profile',$data);

 }
}

请帮帮我。

使用“uri”

  //username
    $username = $this->uri->segment(3, 0);

}
}

当您阅读手册并尝试其中所述内容时发生了什么?example.com/index/testusername…这是我的url…index是我的控制器名称,testusername是参数。我需要将其更改为example.com/testusername.Oh好的,在这种情况下,当您阅读手册并尝试其中所述内容时发生了什么?404页未找到错误啊!有时会发生。干得好
$route['404_override'] = 'profile';

class Index extends CI_Controller {
public function __construct() {
        parent::__construct(); 
}

public function index()
{
    $username = $this->uri_segment(1);

    if (empty($username)) {
        $this->displayPageNotFound();
    }

    // Check if parameter is not a valid username.
    if (!$this->checkIfUsername($username)) {
        $this->displayPageNotFound();
    } else {
       dosomething();
   }