Skip to content
DavisDevelopment edited this page Dec 30, 2014 · 2 revisions
See Also: about-pages

Pages

Pages are, effectively, controller-classes which are associated with route descriptions, and are instantiated when that route is "taken". For instance, if I, in my main Application, write:

* MyApp.hx *
class MyApp extends tannus.Application {
// ...
    
    /**
      * Invoked by the constructor
    **/
    public function beforeStart():Void {

        this.route('*', null, pages.Home);

    }
}

and have a pages package, with a Home class that reads:

* pages/Home.hx *
class Home extends tannus.core.Page {
    public function new(route_taken : tannus.core.Route):Void {
        super( route_taken );
        
        trace( "I have been instantiated! :D" );
    }
}

Upon the invocation of MyApp's start method, you will be able to see "I have been instantiated! :D" printed to the console.

What Sorcery is This?

When you called your Application's route method, you gave it a route-description string, and a Page class to associate with the created Route Object. When the Application was "started", it invoked it's routing system and for every Route that accurately described the current URL, it created a new instance of the Page class associated with that Route. In the case described above, the only route we defined referenced the Home class, and would match any URL, so no matter what, our Home class gets instantiated.