Framework tools
Page
<?php
$page = App::page();
The page method allows retrieving the current page object from anywhere.
<?php
$route = App::getRoute();
The getRoute method allows retrieving the current (cleaned) route name from anywhere (e.g. /contact.html).
/my-page.html = /my-page.html /my-page/ = /my-page /my-page/?q=1 = /my-page /my-page?q=1 = /my-page
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.
The second parameter allows you to change the log level (default is "info").
<?php
App::log('message', Logger::INFO);
Logger::EMERG; // Emergency: system is unusable
Logger::ALERT; // Alert: action must be taken immediately
Logger::CRIT; // Critical: critical conditions
Logger::ERR; // Error: error conditions
Logger::WARN; // Warning: warning conditions
Logger::NOTICE; // Notice: normal but significant condition
Logger::INFO; // Informational: informational messages
Logger::DEBUG; // Debug: debug messages
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>
Search
<?php
$indexes = [
1 => 'Phillip J. Fry',
2 => 'Leela Turanga',
3 => 'Bender Bending Rodriguez',
4 => 'Capitaine Zapp Brannigan',
5 => 'Amy Wong',
];
$search = new Search();
$result = $search->search('leilla captain', $indexes);
array(2) {
[2]=> string(13) "Leela Turanga"
[4]=> string(24) "Capitaine Zapp Brannigan"
}