我的控制器中有以下类(codeigniter)
class Books extends CI_Controller {
function index($id = NULL){
//model
//view
}
}
我的视图文件中有此链接
<a href="<? echo base_url();">/books/index/<? echo $id ;?> > Book1</a>
当我点击上面的链接时,地址栏中的网址看起来像&gt;
http://localhost/my_web/books/index/1
但我想让网址看起来像 -
http://localhost/my_web/books/1
所以,在研究了这个tutorial后,在我的application / config / routes.php中,我使用了以下代码。
$route['books/:num'] = "books/index";
然后我将链接更改为以下代码,但是当我点击它时,页面显示404 Page not found
<a href="<? echo base_url();">/books/<? echo $id ;?> > Book1</a>
你能告诉我们如何实现这个目标吗?
提前致谢:)
答案 0 :(得分:3)
您在路线中缺少参数,请尝试:
$route['books/(:num)'] = "books/index/$1";
答案 1 :(得分:0)
在路由中设置,即application / config / route.php
$route['books/(:any)'] = "books/index/$1";
它绝对适合你的路线。