0

I managed to run default controller from sub directory by adding a MY_Router file in application/core, everything works fine but this is what I am facing now.I am unable to route it if url hits /admin or /student or /teacher which is eventually a sub directory in controllers.

https://s14.postimg.org/pr3ta38f5/controller_structure.png
  https://s14.postimg.org/z05zk7hb5/error_1.png
  https://s14.postimg.org/mmt5darmp/issue_2.png
  https://s14.postimg.org/kwa4bta3l/page_controller.png
  https://s14.postimg.org/j5voo2hy9/routes.png
ArK
  • 20,698
  • 67
  • 109
  • 136
MysticalSam
  • 51
  • 1
  • 10
  • what does your MY_Router look like? also couldn't you just put your controller in a sub-directory and point do it from your router default? $route['default_controller'] = 'directory/controller/method'; – Mehrad Sep 10 '16 at 18:07
  • http://stackoverflow.com/questions/34808054/how-to-use-a-sub-folder-in-default-controller-route-in-codeigniter-3 Here is the MY_Router.php code – MysticalSam Sep 10 '16 at 18:16

1 Answers1

0

If you folder structure is thus:

- controllers
  - teachers
     - Teacher_home.php

  - students
     - Student_home.php

  - admin
     - Admin_home.php

Then normal CI routing would be with URLs to the default index method would be like:

mysite/teachers/teacher_home
mysite/students/student_home
mysite/admin/admin_home

Your routes could then point mysite/teacher_home to the relevant controller above like this:

$route['teacher_home'] = 'teachers/teacher_home';

In the CI docs they describe the wild cards you can use: http://www.codeigniter.com/user_guide/general/routing.html

But any route must point to a valid controller/method url. Get your site/app working under normal default routing, then add the alternate routing in afterwards.

So remove your current routes. If you have a default route in it will probably be messing up your other routes if you have not written it properly, or in the right order.

Hope that helps,

PaulD
  • 1,161
  • 1
  • 9
  • 14