2014-07-18 133 views
0

目前正在使用HMVC笨HMVC路線

的HMVC應用一個笨應用程序包含

$route['finance/bill/add'] = 'finance/show_addBill'; 

$route['finance/transaction/add'] = 'finance/show_addTransaction'; 

$route['finance/(:any)'] = 'finance/$1'; 

$route['finance'] = 'finance'; 

的應用程序有一個財務總監自己routing.php。 當去

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() {} 

我想不通爲什麼上面的路線不工作:S

回答

1

你不應該定義路由在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() FIRST then Modules/Finance/Controllers/Bill(.php)/index()

因此對於您的sc enario你應該有:

$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方法。