Trongate Docs
switch to dark modeswitch to dark mode
»
»
Basic Example - Part 1

Basic Example - Part 1

The best way to understand how the File Asset Manager works is to go through a quick working example.  Let's do that now.

For this example, we'll use the 'welcome' module that comes with all Trongate framework installations.  Our goal, in this example, is to have a JavaScript file stored within a module.  We're then going to display a very simple webpage that executes the module's interval JavaScript file.

The Starting Point

If you have a fresh installation of a Trongate web app then you should have a module named 'welcome' and this module should contain a controller file - namely, Welcome.php.  The 'Welcome' controller file should contain a class with one method.

​<?php
​class Welcome extends Trongate {

    function index() {
​        $this->view('welcome');
​    }

}

Adding A New Method

Let's add a new method onto our controller file.  We'll call the method 'hello' and the method is going to load up a very simple view file that contains the message, 'hello world'.  So, our controller code should now look like this:

​​<?php
​​class Welcome extends Trongate {

    function index() {
​​        $this->view('welcome');
​​    }

    function hello() {
        $this->view('hello');
    }

​​}
​​

A Simple View File

Now, let's create a very view file that contains some HTML.  The example below shows a basic HTML template with the message 'hello world' contained within some h1 tags.   

screenshot


Save your view file using the filename, hello.php. Your view file should be stored inside the views folder, within your 'welcome' module.  

Displaying Content 

If you open your browser and navigate to your app homepage followed by welcome/hello, you should see your 'hello world' message appearing on the screen.

screenshot


HELP & SUPPORT

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

 
×