0

I'm using Codeigniter with HMVC, I Have a sub controller with a name differed from Module name


- modules
      - manage
        - controllers
          - manage.php
        - views
          - dashboard.php

      - properties
         - controllers
            - properties.php
            - manage.php
         - views
            - properties.php
            - manage.php
      - projects 
        - controllers
          - projects.php
          - manage.php
        - views
          - projects.php
          - manage.php

if the url like this (index only working)

sitename.com/manage/proprties

this working fine, but if I passed some parameters,( Error 404) sitename.com/manage/properties/add

OR

sitename.com/manage/properties/edit/10

My Routing like this

$route['manage/(:any)']                     ="$1/manage";
$route['manage/(:any)/(:any)']              ="$1/manage/$2";
$route['manage/(:any)/(:any)/(:num)']       ="$1/manage/$2/$3";

How to make URL sitename.com/manage/properties/edit/10 working?

Ahmed
  • 558
  • 1
  • 4
  • 22

2 Answers2

0

In routes you have wrong. Depending on your version of codeigniter.

https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc

Examples:

$route['default_controller'] =" folder/controller/index"; // Only works codeigniter 2 so far codeigniter 3 will not allow is bug in codeigniter 3

$route['name'] =" folder/controller/index"; // Example

$route['manage'] =" manage/manage/index";

$route['manage/add'] =" manage/manage/add"; 

$route['manage/update/(:any)'] =" manage/manage/update/$1"; // (:any) sbsu2783
$route['manage/update/(:num)'] =" manage/manage/update/$1"; // (:num) 2783
$route['manage/update/(:any)/(:any)'] =" manage/manage/update/$1/$2"; // Just example

$route['manage/delete'] =" manage/manage/delete";

$route['manage/(:any)'] =" manage/manage/index/$1/$2"; // Not need most of the time

sitename.com/manage/edit/10

You may need to include the index.php or may not as not sure if you have configured your htaccess.

For example on controller site_url('manage/update') .'/'. $this->uri->segment(4);

  • my Codeigniter version is `2.1.3` , Using your suggestion, I have to add Routing for each Method, Is this what you mean? – Ahmed Feb 21 '15 at 14:24
  • Yes you need to set routes for each controller some times you will not need the updates `$route['name'] =" folder/controller/function";` is the general way you should use 2.2.1 download from http://www.codeigniter.com/ –  Feb 21 '15 at 14:26
  • but I need to build a way to auto routing modules, many developers build modules using my project ... any another solutions for this problem? – Ahmed Feb 21 '15 at 14:32
0

If you are using HMVC then for calling function of Inner Controller does not require any routing. Just configure it correctly.

Second. name of your module and controller both are same. so when you call localhost/manage it redirects it to manage/manage/index by default but when you call localhost/manage/update it try to find controller named update. so call like this localhost/manage/manage/update

Vishal Rambhiya
  • 741
  • 6
  • 10