1. Go to this page and download the library: Download district5/slimify 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/ */
district5 / slimify example snippets
use DI\Container;
/**
* Build a container
*/
$container = new Container();
/**
* Instantiate App
*/
$app = \Slimify\SlimifyFactory::createSlimify(
$container,
true // Is this the 'development' environment?
);
/**
* Add default view
*/
$app->addView(
'/path/to/view/template/folder',
'/path/to/view/layout.phtml',
[], // params to inject to all views
'default' // the view name (you can have multiple views)
);
/**
* Add a file log.
*/
//$app->addFileLog(
// '/path/to/log/app.log', // log file
// \Monolog\Logger::DEBUG, // log level
// 5, // number of files to keep
// 'app' // logger name
//);
/**
* Add stdout log.
*/
$app->addStdOutLog(
\Monolog\Logger::DEBUG,
'app'
);
/**
* Add router
*/
$app->addRouterWithCache(
'/path/to/cache/routes.php',
true
);
/**
* Add any middleware
*/
// $app->add(new MyMiddleware());
/* @var $app \Slimify\SlimifyInstance */
use Slim\Psr7\Request;
use Slim\Psr7\Response;
$app->get('/', function (Request $request, Response $response, $args) use ($app) {
$app->setInterfaces($request, $response);
return $app->getView()->render(
$response,
'my-view.phtml',
[
]
);
});
$app->post('/json-endpoint', function (Request $request, Response $response, $args) use ($app) {
$app->setInterfaces($request, $response);
$jsonParser = $app->getJsonParser();
$mixedValue = $jsonParser->anything('someKey');
$arrayValue = $jsonParser->array('arrayKey');
$boolValue = $jsonParser->bool('boolKey');
$floatValue = $jsonParser->float('floatKey');
$intValue = $jsonParser->int('intKey');
$stringValue = $jsonParser->string('stringKey');
$mongoIdValue = $jsonParser->mongoId('mongoIdKey');
// Do something with the values...
return $app->response()->json([
'success' => true
]);
])
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.