Php 如何在CodeIgniter中重新映射URL
我需要像CodeIgniter中的facebook一样重定向我的URL 例如:假设我们给出'example.com/username',那么它将显示用户配置文件信息。 但是我的控制器是'example.com/index/username'。这里用户名是参数。 这是我的控制器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();
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();
}