HMVC Integration in Codeigniter view paths

196 views Asked by At

I am trying to intregrate HMVC to codeigniter. I have installed the MX files to thrid_party and uploaded the MY_Loader , MY_Loader and MY_Model to the application/core folder. it is working fine

I have two issues

1) How to add the module routes that overide the application routes

I am accessing module through the link localhost/domain/admin/portfolio

I have tried adding routes.php to the modules config application/modules/portfolio/config/routes.php with below details

 $route['admin/portfolio'] = 'portfolio/admin/portfolio';
 $route['admin/portfolio/add'] = 'portfolio/admin/portfolio/edit';
 $route['admin/portfolio/edit/(:num)'] = 'portfolio/admin/portfolio/edit/$1';

On my root application config already added a routes

$route['admin'] = 'admin/login';

Because of this route 'admin/login' in the application/config/routes.php it is showing page not found. To fix this I have currently added the module/portfolio/config/routes`` above the 'admin/login'. Is there any other method instead of adding it to theapplication/config/routes`.

2) How to access the module view files I have controller accessing the view files from application/controlles/admin/

    $this->load->view('admin/view_header',$data);
    $this->load->view('admin/view_portfolio',$data);
    $this->load->view('admin/view_footer');
1

There are 1 answers

1
TimBrownlaw On

You have placed your Portfolio Controller under

application/modules/portfolio/controllers/admin

which is fine.

Your route (which will hit the index by default) should be

$route['admin/portfolio'] = 'portfolio/admin/portfolio';

Aside: other naming considerations

What I tend to do is to create a controller with admin in the name...

So I would have PortfolioAdmin.php or something along those lines, so I know by the file name, it's admin "Stuff", when I am playing with it in my Editor/IDE.

UPDATE: In regards to your

Nor this works Modules::run('admin/portfolio', $data);

So you would then use the full controller name... Do not use routes, they are for URLs. Any module you want to call from another module you always use the full name.

Modules::run('portfolio/admin/portfolio', $data);