Php codeigniter如何设置控制器类和方法的路由?
我是新来的CI,需要一些专家的初学者帮助 以下是我当前的设置: /控制器/Php codeigniter如何设置控制器类和方法的路由?,php,codeigniter,Php,Codeigniter,我是新来的CI,需要一些专家的初学者帮助 以下是我当前的设置: /控制器/ home.php report.php /观点/ home/index.php home/recent.php report/index.php report/generate.php 我试图生成的URI作为结果: (将加载index.php) (将在报表控制器中调用生成的方法) (将调用主控制器中的generate方法,并传递变量“10”) 如何避免总是修改类中创建的每个新方法的路由文件?因此,它将遵循: $
- home.php
- report.php
- home/index.php
- home/recent.php
- report/index.php
- report/generate.php
非常感谢您的帮助。您不需要进一步修改。事实上,即使这条线也是多余的:
$route['report/(:any)'] = 'report/$1';
$route['/'] = 'home/index';
这也是多余的:
$route['report/(:any)'] = 'report/$1';
$route['/'] = 'home/index';
由于默认控制器设置为“主”且默认方法为始终索引
查看CI如何处理URL:
因此,/localhost/report/generate
将查找report
控制器,并加载其generate
方法。这就是它开箱即用的工作方式,无需布线
这条路线很好:
$route['recent/(:num)'] = 'home/recent/$1';
If将采用URL
/localhost/recent/123
并加载Home
、controller、recent
方法,并将123
作为第一个方法参数传递。谢谢shomz,但我收到一个404错误:在此服务器上找不到请求的URL/recent/10。看起来这很好:。。。如何忽略或排除URL中的index.php?不客气。我在回答中给你的URL中描述了这一点,这里有很多答案,比如:谢谢你为我指明了正确的方向。htaccess更新起了作用。