1. Go to this page and download the library: Download orx0r/slim3-controller 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/ */
orx0r / slim3-controller example snippets
// in index.php
$c = new \Slim\Container;
$c['view'] = function ($container) {
$view = new \Slim\Views\Twig( __DIR__ . '/../templates');
$view->addExtension(new \Slim\Views\TwigExtension(
$container['router'],
$container['request']->getUri()
));
return $view;
};
$app->get('/hello/{name}', 'app\controllers\HelloController:index');
// in app/controllers/HelloController.php
public function actionIndex($name)
{
return $this->render('hello/index.html', ['name' => $name]);
}
// register CallableResolver. pass second parameter as controllerNamespace
$c['callableResolver'] = function ($container) {
return new CallableResolver($container, 'app\controllers');
};
$app->get('/hello/{name}', 'HelloController:index');
php
// in index.php
$app->get('/hello/{name}', 'app\controllers\HelloController:index');
// in app/controllers/HelloController.php
namespace app\controllers;
use Orx0r\Slim\Controller\Controller;
class HelloController extends Controller
{
public function actionIndex($name)
{
return $this->response->getBody()->write("Hello, $name");
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.