Welcome Guest, Not a member yet? Register   Sign In
Codeigniter HMVC to set up custom routes for modules
#1
Wink 
(This post was last modified: 03-30-2015, 07:49 PM by mdixon18.)

I am working quite closely with Codeigniter the PHP framework.

Now I've added this Modular Extensions - HMVC to my Codeigniter framework. https://bitbucket.org/wiredesignz/codeig...c/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:

Code:
$route['posts'] = 'blog';
or if I had a method called listings I could use

Code:
$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?
Reply
#2

(03-30-2015, 07:40 PM)mdixon18 Wrote: Is it possible to create custom routes like this in a module?

It is possible - I've done it a few times before and works as expected.  Not sure if you're using CI2 or CI3, I've only used this feature with CI2 so far.

Quick example of routes in ...modules/cn-pto/config/routes.php

Code:
$route['cn-pto'] = 'cn_pto';
$route['cn-pto/events'] = "cn_pto/events";
$route['cn-pto/update'] = "cn_pto/update";
$route['cn-pto/holidays'] = "cn_pto/holidays";
$route['cn-pto/events/(:num)/(:num)'] = "cn_pto/events/$1/$2";
$route['cn-pto/events/(:num)/(:num)/(:any)'] = "cn_pto/events/$1/$2/$3";
Reply
#3

Works a treat with CI2, just struggling with CI3
Reply
#4

Did you make sure to download Wiredesignz HMVC from the codeigniter-3.x branch? The original version (default branch) won't work with CI3.

https://bitbucket.org/wiredesignz/codeig...gniter-3.x
Reply




Theme © iAndrew 2016 - Forum software by © MyBB