1. Go to this page and download the library: Download comma/core 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/ */
$app = new \Comma\Core();
$app['new_service'] = $app->factory(function(){
return true;
});
$app = new \Comma\Core();
// main page route
$app->route('/', function () {
return 'main page';
});
// news
$app->route('^/news$', function () use ($app) {
return $app->response()->html('<h1>News here</h1>');
});
// or this
$app
->route('^/news$', 'NewsController::indexAction') // where NewsController::indexAction($app)
->inject('comma', $app);
// news by year
$app->route('^/news/{year}$', function ($year) use ($app) {
$tpl = $app->template('path/to/template.php');
$tpl->assign('year', $year);
return $app->response()->view($tpl);
})->assert('year', '\d{4}');
// one article
$app->route('^/news/(\d{4})/(\d+)', function ($year, $id, $tail = null) use ($app) {
return $app
->template('path/to/template.php')
->assign('year', $year)
->assign('id', $id);
});
try {
$app->run($app['request']->server('REQUEST_URI', '/'));
} catch (\Comma\Exception\PageNotFound $ex) {
header('Location: /404');
}
$app = new \Comma\Core();
// You can set base template path
$app['view.config']['path'] = '/base/path';
$tpl = $app->view('path/to/template.php');
$tpl
->assign('first', 'one')
->assign('second', 'two')
->render();
// Getting $_GET vars
$app['request']->vars('GET'); // return array()
// Getting var $_GET['name']
$app['request']->get('name'); // or use $app['request']->__call('GET', 'name') if needed
// Getting var $_GET['name'] or default value
$app['request']->get('name', 'default_value');
// Getting var $_POST['surname']
$app['request']->post('name'); // or use $app['request']->__call('POST', 'name') if needed
// Getting $_FILES
$app['request']->files(); // return array()
// Getting list of files
$app['request']->file('file');
// or getting file with index 0
$app['request']->file('file', 0);
// Getting $_SERVER var
$app['request']->server('SERVER_NAME');
// Getting $_SERVER var or default value
$app['request']->server('SERVER_NAME', 'default_value');