Passing variables to route files?


I have organized my API routes into multiple php files. In the beginning of each, I define the API paths as variables.

$apiPublicBase = "/api/public/v1";

I am now looking to:

  1. Define them in one place, once, for all route files.

  2. Even better if I could access the same definitions in my javascript application. Is this possible?


I believe you could use the configuration file. See :

$config = $app->getContainer()->get('config');

$app->get('/' . $config['assets.raw.path'] . '/{url:.+}', 'UserFrosting\Sprinkle\Core\Controller\CoreController:getAsset');

If your variable is in a config file, it can used in both routes and passed to Javascript.

1 Like