If you’ve found an error, spotted something missing, or feel a section could be clearer or better explained, we’d love to hear from you. Your feedback helps keep the documentation accurate and useful for everyone.
Please report issues or suggest improvements on GitHub. Community input is invaluable in making the docs stronger.
Not comfortable with GitHub? No problem — you can also get in touch with us directly via our contact form. We welcome all feedback.
Loading View Files From Within Child Modules
There may be situations where you'd like to load a view file from within a child module - specifically, by calling (invoking) the view from within a child module's controller. As a reminder, Trongate offers two methodologies for loading of view files. They are:
LOADING VIEWS WITHIN TEMPLATES
Normal Trongate usage usually has view files displayed by defining a 'view_file' property, loading a template and passing the 'view_file'. property into the template request as part of a data array. To achieve this from within a child module, the following two steps are required:
STEP 1: Declare a 'view_module' property, as part of a $data array, within your child module controller file. Make sure your view module contains the name of the parent (super) module then a forward slash followed by the name of the sub (child) module.
STEP 2: Declare a 'view_file' property, as is normal, within your controller file.
EXAMPLE #1
Let's assume you have a super (parent) module called 'forums' and a sub (child) module called 'forum_threads'. Below is an example of syntax that could be used to load a view file from the 'forum_threads' controller.
LOADING VIEWS WITHOUT LOADING TEMPLATES
The example above show how to load a view file whilst loading a template. However, there may be instances where you'd like to load a view file without loading a template. Trongate's default blue page (with the headline "It Totally Works") is an example of scenario where a view file is being called without loading a template.
To achieve this from a child module, the following three steps should be followed:
STEP 1: At the top of your controller file (within your child module), declare a parent and child module inside a constructor method. The parent module should be the name of the module that contains your child module. The child module should be the name of the module from where you are calling your view file.
STEP 2: At the bottom of your controller file (within your child module), use a destructor method to reset the parent and child modules.
STEP 3: Load your view file, from within a method inside your child module, as normal.
EXAMPLE #2
Let's assume you have a super (parent) module called 'paypal' and a sub (child) module called 'shopping_basket'. We'll further assume that our goal is to invoke a method called '_draw_basket()'. The purpose of the _draw_basket() method is to display a view file. Below is an example of syntax that could be used to load a view file from the 'shopping_basket' controller.