目前正在使用HMVC开发CodeIgniter应用程序。
HMVC应用程序有自己的routing.php,其中包含
$route['finance/bill/add'] = 'finance/show_addBill';
$route['finance/transaction/add'] = 'finance/show_addTransaction';
$route['finance/(:any)'] = 'finance/$1';
$route['finance'] = 'finance';应用程序有一个财务控制器。当去
http://localhost/finance** it goes to **public function index(){}
http://localhost/finance/transaction/add DOES NOT go to **public function show_addTransaction() {}
http://localhost/finance/addTransaction DOES goes to **public function show_addTransaction() {}我不明白为什么上述路线不起作用。
发布于 2014-07-18 13:35:02
您不应该在HMVC应用程序中定义路由(这是一条非常强大的经验法则-有例外,但这很少见)。
您应该有一个文件夹结构,如:
Modules
- Finance
- - Controllers
- - - finance //should have index, add and an other generic functions.
- - - transaction // transactions specific functions
- - - bill // bill specific functions.路由是自动的--按照以下思路:
url/finance ->寻找Modules/Finance/Controllers/Finance/Index()
url/finance/bill ->它会先找Modules/Finance/Controllers/Finance(.php)/Bill()然后再找Modules/Finance/Controllers/Bill(.php)/index()
因此,对于您的场景,您应该拥有:
$route['finance/bill/add']bill.php控制器--带有class bill --具有add方法的控制器
$route['finance/transaction/add']transaction.php控制器--带有class transaction --具有add方法的控制器
$route['finance/(:any)']不存在--正如我所说的,URL路由是自动的,所以只要您有相关的控制器和方法,就可以找到
$route['finance']简单的finance.php控制器与index方法。
https://stackoverflow.com/questions/24821860
复制相似问题