• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Load routes from file

#1
Question 
Hi,

Is it possible to load routes from a specific file?

For instance, I have:

Module
    - Config
        - BackedRoutes.php
        - FrontRoutes.php
    (...)

or something like that and I would like to load `FrontendRoutes` only for frontend app and `BackedRoutes` for the admin app. Otherwise, if I have one file `Routes` then after added it to front and backend app I can visit all routes - and it is something what I want to eliminate.

The same problem I will have with `Events` file.

Did anyone have an idea how I can resolve that problem?

Thanks all Smile
Reply

#2
If your routes are in a module they will be searched for and loaded.
loaded.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
I know and I have it now. I understand that will be discovered and loaded automatically.

I have one module responsible for the frontend and backend part and all necessary routes currently I have in `Routes.php`. My goal is to separate frontend routes from backend routes for that one module.
Reply

#4
And if you use this code in the Config/Routes.php file
Add its to 14 line
PHP Code:
$request = new Request(new \Config\App);
if ( 
$request->uri->getSegment(1) == 'admin' ) {
    return \
Config\BackedRoutes;
} else {
    return \
Config\FrontRoutes;

and add to line 3 this use namespace 
PHP Code:
use CodeIgniter\HTTP\Request
Reply

#5
Thx. Great, that makes sense
(04-02-2020, 02:26 PM)FoLez Wrote: And if you use this code in the Config/Routes.php file
Add its to 14 line
PHP Code:
$request = new Request(new \Config\App);
if ( 
$request->uri->getSegment(1) == 'admin' ) {
    return \
Config\BackedRoutes;
} else {
    return \
Config\FrontRoutes;

and add to line 3 this use namespace 
PHP Code:
use CodeIgniter\HTTP\Request
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.