Welcome Guest, Not a member yet? Register   Sign In
HMVC and CMS
#1

[eluser]Unknown[/eluser]
Background:

In the past I have just used the default CodeIgniter install and created models, controllers and views within their respected folders. I noticed that from project to project there was a lot of overlap in the functionality i.e. faqs, page content etc., so I decided to install the HMVC module. The main goal was to group like content (i.e. faqs and faq categories) into like modules so I could move them around from project to project with easy.

I am routing the CMS to the root directory with "admin" appended to it i.e. http://localhost/cms/admin/... using these routes:
Code:
(application/config/routes.php)
$route['admin/([a-zA-Z]+)/(:any)'] = "$1/admin_$2";
$route['^admin/(:any)(/)?'] = "$1/admin_index";
$route['^admin(/)?'] = "dashboard/admin_index";
$route['admin/logout'] = "login/admin_logout";

Issue:

With the addition of the "modules" it allows the application to include the sub-folders within modules in the url like this:
Code:
URL: http://localhost/cms/admin/faqs/index
Directory: application/modules/faqs/controllers/faqs.php - admin_index (method)
-or-
URL: http://localhost/cms/admin/faqs/index
Directory: application/controllers/faqs.php - admin_index (method)

the problem is when I try and to this:

Code:
URL: http://localhost/cms/admin/faqs/categories/index
Routed Directory: application/modules/faqs/controllers/faqs.php - admin_categories (method)
Desired Directory: application/modules/faqs/controllers/categories.php - admin_index (method)

I understand that because the application can now look in two places, I cannot depend on the URL being simply "controller/method", it can also be "module/controller/method".

I have tried to attack this by overwriting the core, but with no result.

Thank you in advance if you can help.
#2

[eluser]theprodigy[/eluser]
Quote:(application/config/routes.php)
$route['admin/([a-zA-Z]+)/(:any)'] = "$1/admin_$2";
$route['^admin/(:any)(/)?'] = "$1/admin_index";
$route['^admin(/)?'] = "dashboard/admin_index";
$route['admin/logout'] = "login/admin_logout";
I think it is your first route that is causing your issue.
Routes are read from top down. Once it comes across a route that fits, it uses it and drops the rest.
In this case
Quote:URL: http://localhost/cms/admin/faqs/categories/index
Routed Directory: application/modules/faqs/controllers/faqs.php - admin_categories (method)
Desired Directory: application/modules/faqs/controllers/categories.php - admin_index (method)
it's following that route to:
faqs/admin_categories

My suggestion, either move or remove the first route. If you move it down, it should hit the "second" route first (as it would now be first in line), and give you the desired results.




Theme © iAndrew 2016 - Forum software by © MyBB