Welcome Guest, Not a member yet? Register   Sign In
Route configuration for sub-directory.
#1

[eluser]Unknown[/eluser]
Good day,

I recently jumped on the wagon of using CodeIgniter and have so far enjoyed the simplicity and ease of use, but has come to an halt and probably due to lack of knowledge on what to search for I am coming up empty with a solution.

On the project I am currently working on I have a controller called Page, which is handling all requests at the moment and using the uri segments to determine the view and a function for the view. All this is working great as intended. To get to this, I have used the following configuration in routes.php
Code:
$route['default_controller'] = "page";
$route['(.*)'] = 'page';
$route['404_override'] = '';

Now I want to create a second controller to handle Ajax requests. My folder structure looks something as follow:
Code:
+ application
  + controllers
    - ajax.php
    - page.php
  + views
    + ajax
      - test.php
    - default.php

I am able to easily create additional views either in the views directory or sub directories. But with the above routes.php config as you would know the page controller will be used. Changing the config.php to the following one would assume it would override the route for the specific sub-folder, but it doesn't seem to.
Code:
$route['default_controller'] = "page";
$route['(.*)'] = 'page';
$route['(./ajax/*)'] = 'ajax';
$route['404_override'] = '';

Any advice towards a solution would be appreciated.

Thanks
#2

[eluser]CroNiX[/eluser]
Many posts about that on the forums. The routes work from top down, and will get triggered on the FIRST match. So if your catch-all route (*) is before any other route, nothing will make it past it because * matches everything and sends it to the page controller.

The order should be (these 2 always first)
default_controller
404_override

then custom routes (most specific to least specific)
ajax
*

so if it doesn't match the default_controller, it will try 404_override. If that doesn't match it will try ajax. If that doesn't match it will send it to your catchall page controller.
#3

[eluser]Unknown[/eluser]
[quote author="CroNiX" date="1381422319"]Many posts about that on the forums. The routes work from top down, and will get triggered on the FIRST match. So if your catch-all route (*) is before any other route, nothing will make it past it because * matches everything and sends it to the page controller.

The order should be (these 2 always first)
default_controller
404_override

then custom routes (most specific to least specific)
ajax
*

so if it doesn't match the default_controller, it will try 404_override. If that doesn't match it will try ajax. If that doesn't match it will send it to your catchall page controller.[/quote]

Hi,

Yes, I did find much more relevant with the info from your reply. Just a matter of no idea what to search for exactly.

Thanks for helping me solve this one.




Theme © iAndrew 2016 - Forum software by © MyBB