Global objects

Sometimes you need to have some global objects in your application (for example, logged in user). In HaQuery you may add member variables to your base page class and extends all other classes from it.

src/pages/layout/Page.hx file:

package pages.layout;

class Server extends BaseServer
{    
    // here Users is your class for user info
    public var user : Users; 
}

After that you may access current user from any page or component:

class Server extends BaseServer
{
    function init()
    {
        // set or get page.user:
        page.user = page.db.orm.users.get(page.cookie.get("userID"));
    }
}

You can do the same for the client too.

One thing: "page" variable has a HaqPage type by default, so you need to cast it to the pages.layout.Server. To avoid this, you may specify new page type on your FlashDevelop's project settings/build/pre-build step:

haxelib run HaQuery build --base-page=pages.layout

version #224, modified 2013-10-12 16:19:40 by yar3333