Trongate Docs
switch to dark modeswitch to dark mode
»
»
The Module Assets Trigger

The Module Assets Trigger

In the example from the previous page, we managed to serve a JavaScript file that was stored deep within the bowels of our 'modules' directory.  However, the file path that we referenced, to load the JavaScript file, was surprisingly short and simple.  As a reminder:

screenshot

Under normal circumstances, this kind of file path should have produced a 404 (not found) error.  However, the reason why the JavaScript file successfully loaded in our example is because our file path invoked Trongate's Module Assets Trigger.

What Is The Module Assets Trigger?

The Module Assets Trigger is a special string (i.e., a group of characters) that can be included as part of a website URL or a file path.  If a resource is called that contains the special string as part of the file path, then the File Asset Manager will be called into action.  The File Asset Manager will assume that the asset being referenced exists within a module's assets directory.  Assuming the file exists, the File Asset Manager will then automatically deduce which module to fetch the file from.  Then, the File Asset manager will generate appropriate headers based on the type of file that was called.  So, the file that has been called with be loaded and the developer can enjoy truly modular development.

By default, the 'trigger' for the Trongate framework's File Asset Manager is the string '_module'.  So, if a file path contains '_module' then Trongate will automatically assume that the file must be contained within a module's assets folder.

WARNING!
If any website URL or file path, on your app, contains the Module Assets Trigger then the File Assets Manager will attempt to load a file from within a module.  Therefore, it's important to only include the Module Asset Trigger string in scenarios where you're trying to load an asset from within a module.  If you accidentally include the module assets trigger inside a URL, then there's a high possibility of some very confusing 404 errors.

How It Works

Your Module Assets Trigger is set inside your config.php file.  Specifically, on this line:

​define('MODULE_ASSETS_TRIGGER', '_module');

This line of code tells the Trongate Framework to check website URLs and path files for the string '_module'.  If the string is found (within a URL or a file path), Trongate will figure out which module to reference by looking at the characters immediately before the Module Assets Trigger.

So, if you happen to have a file stored within a module called 'cars' then your file path should start with:

cars_module/

This file path tells Trongate that you want to load a file from within the 'cars' module, but - more specifically - a file that's stored within the 'assets' subdirectory that's inside the 'cars' module.

Therefore, whenever you see a module name in a file path or URL, followed by underscore module (_module) then you should assume that the assets directory of the named module is being referenced.

Changing The Module Assets Trigger

If you want, you can easily change the module trigger phrase (on config.php) to suit your individual needs.  This means that you can choose what string invokes the file asset manager.  To do this, simply open up config.php and change the value assigned to the MODULE_ASSETS_TRIGGER.  

Top Tip
When you're building an app that accepts data from the public, it might be a good idea to create some validation rules that prevent users from creating pages that might invoke the file asset manager.  For example, if you have a page that creates URLs based off of usernames, then site visitors should not be allowed to create usernames that contain the Module Trigger Phrase.

Having said that, don't worry!  There's no major risk of attack here.  The worst case scenario is a 'not found' error.


HELP & SUPPORT

If you have a question or a comment relating to anything you've see here, please goto the Help Bar.

 
×