开发者

Codeigniter HMVC and CMS

I am using Codeigniter with the HMVC Modular extension and have a backend CMS area for managing website content. I am routing the base URL + "admin" (http://localhost/cms/admin) to controller methods with the prefix "admin_".

e.g. function admin_index() {...}

And here is my routing:

$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";

With the HMVC it is not routing correctly now. Here is what happens:

URL: http://localhost/cms/admin/faqs
Directory: modules/faqs/controllers/faqs - index method
--
here is where it breaks
--
URL: http://localhost/cms/admin/faqs/categories
Directory: modules/faqs/controllers/faqs - categories method (does not exits)
Desired: modules/faqs/controllers/categories - index method

How can I use HMVC while maintaining the "admin" ar开发者_如何转开发e of the website?


You are making life a bit too tricky by putting frontend and backend functions in the same controllers. Have a look at my article on how to create an admin structure in CodeIgniter.


I'm working on something similar, and implemented a swapping like you did (3rd option) and it worked fine.

I tried to implement a front controller to handle the admin section, and run modules with HMVC modules::run() and buffer the output as I wish, but then I have faced another issue, you will have to change the URI schemes from / to _ or something else, since you wont be able to send module segments as parameter to your controller because CI relies on "/" for it's routing mechanism.

The only way is to emulate the admin section as Phil suggested, but there is another option to still have control over the code implemented by anyone using your CMS.

You could extend CI_Controller (or MX_Controller in case you are using HMVC) and add an Admin_Controller which will handle your logic and control what modules can do.

Have a look at this CodeIgniter Base Classes: Keeping it DRY

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜