PHP code example of arvici / framework
1. Go to this page and download the library: Download arvici/framework library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
arvici / framework example snippets
Router::define(function(Router $router) {
$router->get('/', '\App\Controller\Welcome::index');
$router->get('/session', '\App\Controller\Welcome::session');
$router->get('/json', '\App\Controller\Welcome::json');
$router->get('/exception', '\App\Controller\Welcome::exception');
});
Configuration::define('database', function() {
return [
/**
* The default fetch type to use.
*/
'fetchType' => \Arvici\Heart\Database\Database::FETCH_ASSOC,
/**
* Database Connection names and configuration values.
*
* 'default' is used when no connection name is provided, or using SweetORM.
*/
'connections' => [
'default' => [
'driver' => 'MySQL',
'host' => 'localhost',
'username' => 'root',
'password' => '',
'port' => 3306,
'database' => 'arvici_test'
],
]
];
});
Configure::define('cache', function () {
return [
/**
* Enable cache.
*/
'enabled' => true,
/**
* Set to true to enable cache even in non-production mode.
*/
'forceEnabled' => true,
/**
* Cache Pool Configuration.
*/
'pools' => [
'default' => [
'driver' => '\Stash\Driver\FileSystem',
'options' => [
'path' => BASEPATH . 'cache' . DS,
]
],
],
];
});
$manager = \Arvici\Component\Cache::getInstance();
$pool = $manager->getPool(); // pool name = 'default'
// or with a pool name:
$pool = $manager->getPool('redis-cache'); // pool name = 'redis-cache'
$item = $pool->get('test/cachingkey');
$item->set($data);
$expiration = new DateTime('2020-01-21');
$item->expiresAfter($expiration);
$item->save();
$data = $item->get();
$item->isMiss(); // bool