Welcome Guest, Not a member yet? Register   Sign In
Routing and modules
#1

I'm trying to separate my project in different modules.

I've the following modules
- admin
- portal
- site

The main controller is site, there is where users land for the first time. Here are my routes on Modules\Site\Config\Routes.php

PHP Code:
/**
 * --------------------------------------------------------------------
 * Router Setup
 * --------------------------------------------------------------------
 */
$routes->setDefaultNamespace('Modules\Site\Controllers');
$routes->setDefaultController('Home');
$routes->setDefaultMethod('index');
$routes->setTranslateURIDashes(false);
$routes->set404Override();
$routes->setAutoRoute(true);

/**
 * --------------------------------------------------------------------
 * Route Definitions
 * --------------------------------------------------------------------
 */

// We get a performance increase by specifying the default
// route since we don't have to scan directories.
$routes->add('/''Home::index'); 

This works perfectly. When I request the home page or any other controller on that namespace works without issues. If I request /register or /recover or /about it works.

The problem starts when trying to use any of the other modules, let's use admin as an example.

This is my Routes.php file inside the admin module. (Modules\Admin\Config\Routes.php)
PHP Code:
/**
 * --------------------------------------------------------------------
 * Router Setup
 * --------------------------------------------------------------------
 */
$routes->setDefaultNamespace('Modules\Admin\Controllers');
$routes->setDefaultController('Home');
$routes->setDefaultMethod('index');
$routes->setTranslateURIDashes(false);
$routes->set404Override();
$routes->setAutoRoute(true);

/**
 * --------------------------------------------------------------------
 * Route Definitions
 * --------------------------------------------------------------------
 */

// We get a performance increase by specifying the default
// route since we don't have to scan directories.
$routes->add('admin''Home::index'); 

The root of admin works well, so if I try to access the home works. Doing http://myurl.com/admin or http://myurl.com/admin/index

What I don't understand is why http://myurl.com/admin/login won't work, I'm just calling one of the methods inside the Home controller in admin.

I always get the following error


Code:
404 - File Not Found
Controller or its method is not found: {0}::{1}

Debugging that I get

Code:
string(34) "\Modules\Lobby\Controllers\Admin" string(5) "login"

Clearly it's not finding Admin::login because the namespace is wrong, but all that is set on Routes.php config file.

Two clarifications:
  • My App\Config\Routes.php file has all the routing lines commented. Not default things neither added routes.
  • My Modules are outside the App folder.
  • root/app
  • root/modules/portal
  • root/modules/site
  • root/modules/admin
Any pointer on what I might be missing here? The portal has the same setup, and produces the same issue.
Reply


Messages In This Thread
Routing and modules - by lucky - 11-24-2020, 12:33 AM
RE: Routing and modules - by InsiteFX - 11-24-2020, 06:52 PM
RE: Routing and modules - by lucky - 11-25-2020, 12:29 AM
RE: Routing and modules - by InsiteFX - 11-25-2020, 03:46 PM
RE: Routing and modules - by lucky - 11-26-2020, 12:20 AM
RE: Routing and modules - by InsiteFX - 11-26-2020, 03:04 AM
RE: Routing and modules - by lucky - 11-26-2020, 09:57 AM
RE: Routing and modules - by InsiteFX - 11-26-2020, 12:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB