Codeigniter with subfolders and uri segments

461 Views Asked by At

I have a site called: orders.

In the controllers folder I have a sub folder called: manage.

In there I have a controller called: editOrder

In the editOrder controller I have an index function that get an $id as a parameter.

In one of my forms I have a link to: editOrder/1

In my route file I have this code: $route['editOrder'] = 'manage/editOrder'; The link gives the error page not found.

I tried to go to the page manually, like this: http://localhost/orders/editOrder/1 Page not found

I tried this way:

In my route file:

$route['editOrder/(:num)'] = "manage/editOrder/$1";

Page not found

I have changed my config file to:

$config['uri_protocol'] = 'PATH_INFO';

$config['enable_query_strings'] = TRUE;

And tried this way:

http://localhost/orders/?c=editOrder&m=index&id=1

That takes me to the home page.

How can I pass the id segment to the editOrder controller?????

Ahhhhhhhhhh

How would I call this controller????

1

There are 1 best solutions below

0
On

Make sure:

  1. Your custom route comes after the 2 default ones. So it should be:

    $route['default_controller'] = "defaultController";
    $route['404_override'] = '';
    $route['editOrder/(:num)'] = "manage/editOrder/index/$1";
    
  2. Your controller file editOrder.php has a class editOrder extends CI_Controller and is inside the folder "controllers/manage/";

  3. Your editOrder controller has a function index($id) {} method;

To sum up, if you're going to call a method, you need to specify it. In case of routing, that means you have to specify even the index() method.