0

I am working quite closely with Codeigniter the PHP framework: http://www.codeigniter.com/

Now I've added this Modular Extensions - HMVC to my Codeigniter framework. https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/overview

Now, I've created my own module in the modules folder and set up directories for controllers, models and views as instructed. However I'm struggling specifically with custom routing.

I have created the config directory in my module blog directory and I have created the routes.php file within.

Now to access my module in the browser i would go to localhost:8888/blog/ now I'm mostly asking out of curiosity, I wanted to create a custom route so that maybe I could access the page like localhost:8888/posts/ so I thought that setting up the following route would work:

$route['posts'] = 'blog';

or if I had a method called listings I could use

$route['posts/listings'] = 'blog/listings';

However this returns a 404 Page Not Found.

Is it possible to create custom routes like this in a module?

mdixon18
  • 1,199
  • 4
  • 14
  • 35

1 Answers1

3

Setting up custom routes for HMVC Easy here are some examples below. You can use same techneique for CI3 Make sure you choose right version from here https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/downloads go to branches and choose your version The Default is for CI-2

$route['default_controller'] = 'catalog/common/welcome/index';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

// Common
$route['admin'] = "admin/common/login/index";
$route['admin/dashboard'] = "admin/common/dashboard/index";
$route['admin/logout'] = "admin/common/logout/index";
$route['admin/register'] = "admin/common/register/index";

// Users
$route['admin/users/user_edit/(:any)'] = "admin/user/users/user_edit/$1";
$route['admin/users/user_password/(:any)'] = "admin/user/users/user_password/$1";
$route['admin/users/user_key/(:any)'] = "admin/user/users/user_key/$1";

For Example:

admin will be module name.

application modules / admin <-- Admin Module Name

application / modules / admin / controllers / common <-- Sub folder
application / modules / admin / controllers / users <-- Sub folder

Please watch this great tutorial for beginners on HMVC https://www.youtube.com/watch?v=8fy8E_C5_qQ

You can also download Htaccess from here http://www.insiderclub.org/downloads you may need to join for free to download David's Insider Club suitable for codeigniter.

  • I am using it and have no issuse did you download the right version of HMVC there are two versions of HMVC in the download then go to branches –  Mar 31 '15 at 10:04
  • Anybody still looking for a working link should just google "codeigniter hmvc download" and will get multiple options from which they can use. Thanks to Mr. ED for adding that video tutorial, it was really helpful. – Anupam Mar 21 '21 at 00:08