MageWork

Back to home

Framework tools

Page

<?php

$page = App::page();

$route = App::getRoute();

The page method allows retrieving the current page object from anywhere.

The getRoute method allows retrieving the current route name from anywhere (e.g. /contact.html).

Encryption

<?php

$var = App::encryption()?->crypt('message');

echo App::encryption()?->decrypt($var);

The encryption key is stored in var/encryption. If the key is lost, it will be impossible to decrypt the data ever again.

Cache

<?php

App::cache()?->set('foo', 'bar');

echo App::cache()?->get('foo');

The cache file is stored in var/cache. The default cache lifetime is 86400. You can update the lifetime before variable assignment:

<?php

App::cache()?->setLifetime(3600)->set('foo', 'bar');

Session

<?php

App::session()?->set('foo', 'bar');

echo App::session()?->get('foo');

The sessions are stored in var/session.

Log

<?php

App::log('message');

The logs are stored in var/log.

Database

<?php

$id = App::db()->insert('table', ['name' => 'John Doe']);

App::db()->query('UPDATE table SET name = ? WHERE id = ?', ["Jane Doe", 1]);

$result = App::db()->query('SELECT * FROM table')->fetchAll();

$result = App::db()->query('SELECT * FROM table WHERE id = ?', [1])->fetch();

Config

<?php

echo App::getConfig('app.domain');

Escaper

<?php

App::escapeHtml('<a href="#">Escaped HTML</a>');

App::escapeHtmlAttr('my-class');

App::escapeUrl('https://www.example.com');

App::escaper()->escapeQuotes("that's true");
<a href="#" onclick="javascript:alert('<?= App::escaper()->escapeQuotes("that's true") ?>')">Alert</a>