Welcome Guest, Not a member yet? Register   Sign In
HMVC: Routing issue
#1

[eluser]qpixo[/eluser]
I'm using HMVC method but having trouble with routing issue.

Does anyone know how to setup a normal site and login part? I can't make the routing work correctly

For example, I want to achieve when user is typing http://www.test.com, it will load normal site
and http://www.test.com/login, it will load login form

Currently, both is located in modules directory



#2

[eluser]weboap[/eluser]
normally with the hmvc you will have
Code:
/application
/application/modules
/application/modules/module1
/application/modules/module1/home        (controller)
/application/modules/module1/login       (controller)
/application/modules/module2/....    other controllers... in module1


/application/modules/module2
/application/modules/module2/some_default_controller
/application/modules/module2/....    other controllers... in module2

/application/modules/module3
/application/modules/module3/some_default_controller
/application/modules/module3/....    other controllers... in module3


... you get the picture



in module 1 the relation between controllers and the long controller is basically in every controller you test if the user is logged in, if yes run the controller methods if NO redirect to login.....


another step to make https://bitbucket.org/wiredesignz/codeig.../wiki/Home

work is the
routing part

it will be as per the example above in config/routes like

Code:
$route['^(?!module2|module3).*'] = "module1/$0";
$route['module2/(:any)'] = "module2/$1";
$route['module3/(:any)'] = "module3/$1";


hope it help

#3

[eluser]qpixo[/eluser]
[quote author="weboap" date="1337204285"]normally with the hmvc you will have

another step to make https://bitbucket.org/wiredesignz/codeig.../wiki/Home

work is the
routing part

it will be as per the example above in config/routes like

Code:
$route['^(?!module2|module3).*'] = "module1/$0";
$route['module2/(:any)'] = "module2/$1";
$route['module3/(:any)'] = "module3/$1";


hope it help

[/quote]

Yes this is what I'm using with MX_Controller but I'm having trouble with my route

HMVC structure:

Code:
// Login
application/modules/login/controllers
application/modules/login/models
application/modules/login/views
application/modules/login/config/routes.php

// Site
application/modules/site/controllers
application/modules/site/models
application/modules/site/views
application/modules/site/config/routes.php

Login routes file
Code:
$route['login'] = "login/index";


Site routes file
Code:
$route['(:any)'] = "site/index";
$route['(:any)'] = "site/loadPage/$1";

The problem is: It doesn't recognize http://www.site.com/contact or http://www.site.com/about
As error it says: Page request not found
#4

[eluser]InsiteFX[/eluser]
Each module can have its own config and route file!
#5

[eluser]qpixo[/eluser]
[quote author="InsiteFX" date="1337272680"]Each module can have its own config and route file!
[/quote]

this is what I've done for each...
#6

[eluser]weboap[/eluser]
the modules routes
Code:
$route['^(?!module2|module3).*'] = "module1/$0";
$route['module2/(:any)'] = "module2/$1";
$route['module3/(:any)'] = "module3/$1";

should be before that the system get to the modules, if you get what mean so that part need to be in the main
/config/routes
like:

Code:
[code]
$route['^(?!site|backend|....).*'] = "login/$0";
$route['site/(:any)'] = "site/$1";
$route['backend/(:any)'] = "backend/$1";

Note: i'm here just applying your structure.

what i think it should be like is :

Code:
$route['^(?!login|backend|....).*'] = "site/$0";
$route['login/(:any)'] = "login/$1";
$route['backend/(:any)'] = "backend/$1";



Code:
$route['login'] = "login/index";  // not needed

not needed as in you module local route

login been the module and the index your default controller
/application/modules/module1/config/routes.php
Code:
$route['default_controller'] = "index";

doing it this way you can get access to the controllers under site as
http://www.site.com/controllers_name


controllers under login module or backend module will be

http://www.site.com/login/controllers_name

http://www.site.com/backend/controllers_name



hope it help.
note the way you are doing it now
to access the contact controller will be like
http://www.site.com/site/contact

hope it help


#7

[eluser]qpixo[/eluser]
[quote author="weboap" date="1337278574"]the modules routes
Code:
$route['^(?!module2|module3).*'] = "module1/$0";
$route['module2/(:any)'] = "module2/$1";
$route['module3/(:any)'] = "module3/$1";

should be before that the system get to the modules, if you get what mean so that part need to be in the main
/config/routes
like:

Code:
[code]
$route['^(?!site|backend|....).*'] = "login/$0";
$route['site/(:any)'] = "site/$1";
$route['backend/(:any)'] = "backend/$1";

Note: i'm here just applying your structure.

what i think it should be like is :

Code:
$route['^(?!login|backend|....).*'] = "site/$0";
$route['login/(:any)'] = "login/$1";
$route['backend/(:any)'] = "backend/$1";



Code:
$route['login'] = "login/index";  // not needed

not needed as in you module local route

login been the module and the index your default controller
/application/modules/module1/config/routes.php
Code:
$route['default_controller'] = "index";

doing it this way you can get access to the controllers under site as
http://www.site.com/controllers_name


controllers under login module or backend module will be

http://www.site.com/login/controllers_name

http://www.site.com/backend/controllers_name



hope it help.
note the way you are doing it now
to access the contact controller will be like
http://www.site.com/site/contact

hope it help


[/quote]

I'm a bit confused about your example, I have the default application/config/routes.php file and two others routes files in modules directory (application/login/config/routes.php and application/site/config/routes.php) Where on each routes file should I add those lines?

My current default application/config/routes.php contains
Code:
$route['default_controller'] = "site";

What I'd like to do is when user typing:
http://www.site.com/login It will load in login form

http://www.site.com/ and, or http://www.site.com/contact It will load in public normal site

#8

[eluser]weboap[/eluser]
quick question: is there a reason you are trying to set login as a separate module? not a controller?
#9

[eluser]qpixo[/eluser]
[quote author="weboap" date="1337280916"]quick question: is there a reason you are trying to set login as a separate module? not a controller?[/quote]

cause I want to experiment/learn HMVC structure.
I think most intermediate and complex websites use it...
#10

[eluser]weboap[/eluser]
in : application/config/routes.php

Code:
//add
$route['^(?!login|backend).*'] = "site/$0";
$route['login/(:any)'] = "login/$1";
$route['backend/(:any)'] = "backend/$1";  //just another module if you want




in application/modules/login/routes.php

Code:
//change to
$route['default_controller'] = "login_default_controller_name";  
// no other routes at the moment.

in application/modules/site/routes.php

Code:
//change to
$route['default_controller'] = "site_default_controller";  
// no other routes at the moment.


in application/modules/backend/routes.php

Code:
//change to
$route['default_controller'] = "backend_default_controller";  
// no other routes at the moment.


that should do it.




Theme © iAndrew 2016 - Forum software by © MyBB