• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HMVC - Access several controllers for same module

#1
[eluser]vdecaux83[/eluser]
Hello there,

I am using HMVC (https://bitbucket.org/wiredesignz/codeig...sions-hmvc).

But I have one question..

Is it possible to have several controllers in the same module folder ? Here is my folders :

/modules
/mymodule
/controllers
mymodule.php
admin.php

How can I access by uri to admin controller ? I tried :

domain.com/mymodule/admin/method_name

But its not works. Is there a way to do this ? Thanks !

#2
[eluser]ivantcholakov[/eluser]
That magic hides in application/config/routes.php. Here you are a real one from an application of mine:

Code:
$route['default_controller']                = 'home';

if (stripos($_SERVER['REQUEST_URI'], '/admin') !== false) {
    $route['404_override'] = 'admin/error_404';
} else {
    $route['404_override'] = 'error_404';
}

$route['translate_uri_dashes'] = TRUE;

$route['admin/([a-zA-Z_-]+)/(:num)']        = '$1/admin/index/$2';
$route['admin/([a-zA-Z_-]+)/(:num)/([a-zA-Z_-]+)'] = '$1/admin/$3/index/$2';
$route['admin/([a-zA-Z_-]+)/(:num)/([a-zA-Z_-]+)/([a-zA-Z_-]+)'] = '$1/admin/$3/$4/$2';
$route['admin/([a-zA-Z_-]+)/(:num)/([a-zA-Z_-]+)/([a-zA-Z_-]+)/(:num)'] = '$1/admin/$3/$4/$2/$5';
$route['admin/([a-zA-Z_-]+)/(.+)']          = '$1/admin/$2';
$route['admin/([a-zA-Z_-]+)']               = '$1/admin/index';

$route['([a-zA-Z_-]+)/(:num)']              = '$1/index/$2';
$route['([a-zA-Z_-]+)/(:num)/([a-zA-Z_-]+)/(:num)'] = '$1/$3/$2/$4';

$route['sitemap.xml']                       = 'sitemap/xml';

Not everything inside is related strictly to the subject. And this is a sample structure of an application:

Code:
application/
    modules/
        admin/
            controllers/
                Admin.php (admin home)
                Error_404.php
        error_404/
            controllers/
                Error_404.php (for the public site)
        home/
            controllers/
                Home.php (public home)
        pages/
            controllers/
                Admin_pages.php (admin home for "pages" module)
                Pages.php (public home for "pages")
etc.

This way is possible, I have real applications using it. But I don't like it. :-) I have two applications ("site" and "admin") and I am mixing artificially them within a single application.

----------------------------------------------------------

It would be better "site" and "admin" applications to be implemented with separation and I am experimenting this next (logical) step.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.