Php Codeigniter URI:创建默认控制器函数

Php Codeigniter URI:创建默认控制器函数,php,codeigniter,codeigniter-2,codeigniter-routing,Php,Codeigniter,Codeigniter 2,Codeigniter Routing,我的控制器中有以下类(codeigniter) 我的视图文件中有此链接 <a href="<? echo base_url();">/books/index/<? echo $id ;?> > Book1</a> 但我正在努力使URL看起来像- http://localhost/my_web/books/1 因此,在研究了这一点之后,在我的应用程序/config/routes.php中,我使用了以下代码 $route['books/

我的控制器中有以下类(codeigniter)

我的视图文件中有此链接

<a href="<? echo base_url();">/books/index/<? echo $id ;?>  > Book1</a>
但我正在努力使URL看起来像-

     http://localhost/my_web/books/1
因此,在研究了这一点之后,在我的应用程序/config/routes.php中,我使用了以下代码

$route['books/:num'] = "books/index";
然后我将我的链接改为下面的代码,但当我点击它时,页面显示
404页面未找到

   <a href="<? echo base_url();">/books/<? echo $id ;?>  > Book1</a>

你能告诉我如何做到这一点吗


提前感谢:)

如果路由中缺少参数,请尝试:

$route['books/(:num)'] = "books/index/$1";

路由中缺少参数,请尝试:

$route['books/(:num)'] = "books/index/$1";

在路径中设置,路径为application/config/Route.php

$route['books/(:any)'] = "books/index/$1";

它绝对适合您的路由。

在路径中设置,即application/config/route.php

$route['books/(:any)'] = "books/index/$1";

它绝对适合你的路线。

我认为:
$route['books/:num']=“books/index/$1”–正如您链接到的教程中所述;)我想:
$route['books/:num']=“books/index/$1”–正如您链接到的教程中所述;)更正<代码>$route['books/(:num)]='books/index/$1'
必须将
:num
括在括号中,否则它将匹配,但与
$1
;)无关更正<代码>$route['books/(:num)]='books/index/$1'
必须将
:num
括在括号中,否则它将匹配,但与
$1
;)无关