我正在使用CodeIgniter。例如,我的网站是test.com
我的默认控制器是 Home
Home
控制器代码
class Home extends CI_Controller
{
public function index($firstname = NULL, $lastname = NULL)
{
if(!$firstname && !$lastname)
{
$this->load->view('home_view');
}
else
{
echo "First Name = " . $firstname . "<br>";
echo "Last Name = " . $lastname ;
}
}
}
当输入类似URL时test.com
,它将产生输出形式home_view
,并且可以。
当输入类似URL时test.com/home/index/Michael/Clarke
,得到以下输出:
First Name = Michael
Last Name = Clarke
我想在URL上方test.com/Michael/Clarke
而不是test.com/home/index/Michael/Clarke
。
如何移除home/index
?
在你的 application\config\route.php
//UPDATE
// to achive example.com/firstname/lastname, use this route.
$route['(:any)/(:any)'] = "test/index/$1/$2";
在你的控制中
public function index($first, $second){
echo "first ".$first."<br>";
echo "second ".$second;
}//end function
将打印example.com/ARIFUL/haque
为
first ARIFUL
second haque
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句