1. Go to this page and download the library: Download h4d/leveret 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/ */
h4d / leveret example snippets
$app = new Application();
$app->registerRoute('GET', '/hello/:string')
->setAction(
function ($name) use ($app)
{
$app->getResponse()->setBody('Hello '.$name);
});
$app->run();
$app = new Application(APP_CONFIG_DIR.'/config.ini');
$app->setAutoRequestValidationMode(Application::AUTO_REQUEST_VALIDATION_MODE_REQUEST_VALIDATION_BEFORE_AUTH);
$this->registerRoute('POST', '/create/alias')
->addRequestFilters('alias', [new Filter1(), new Filter2(),
function($alias){return strtolower($alias)}]);
$app->run();
use H4D\Leveret\Application;
use H4D\Leveret\Application\Controller;
use H4D\Leveret\Http\Response\Headers;
class MathController extends Controller
{
/**
* Sobreescribo método init
*/
public function init()
{
// Especifico el layout que se utilizará para todas las acciones de este controller
$this->useLayout('layouts/main.phtml');
}
/**
* @param float $a
* @param float $b
*/
public function add($a, $b)
{
// Obtengo la vista y paso las variables necesarias.
$this->getView()
->addVar('title', sprintf('%s + %s', $a, $b))
->addVar('num1', $a)
->addVar('num2', $b)
->addVar('result', $a+$b);
// Especifico la pantilla que se va a emplear.
$this->render('add.phtml');
}
public function info()
{
// No uso vista, seteo directamente el cuerpo de la respuesta.
$this->getResponse()->setBody(phpinfo());
}
}