Routing controllers in subfolders using CodeIgniter

前端 未结 3 1465
独厮守ぢ
独厮守ぢ 2020-11-29 09:55

since i want to separate the frontend and backend of the system. i have created 2 folders inside controllers as frontend and backend

Below is the structure of my con

相关标签:
3条回答
  • 2020-11-29 10:39

    Do this:

    $route['store/(:any)'] = 'frontend/store/$1';
    $route['processing/(:any)'] = 'frontend/processing/$1';
    $route['profile/(:any)'] = 'frontend/profile/$1';
    

    Same for backend :

    $route['backend/(:any)'] = 'backend/authenticate/$1';
    

    You don't have to create each rule in routes.php for every function of the controller, rather one rule per controller will be enough as mentioned above.

    URI Routing : CodeIgniter User Guide

    $1 represent the first expression, here (:any) is the expression, you can have multiple expression on each rule, and expression is represented as $1, $2 and so on on the other side.

    Similarly, (:num) will match a segment containing only numbers, (:any) will match a segment containing any character, (\d+) will match any digit, ([a-z]+) will match any alpha text.

    0 讨论(0)
  • 2020-11-29 10:41

    For Front-End you can add this in routes.php:

    $this->set_directory( "frontend" );
    

    so in browser URL, there is no need to include "frontend"

    0 讨论(0)
  • 2020-11-29 10:44

    You have to be able to differentiate the frontend from the backend somehow. Maybe set a route that forwards any uri with "admin" to the backend, and anything without "admin" to the frontend.

    0 讨论(0)
提交回复
热议问题