PHP code example of fudge / silex-container-aware

1. Go to this page and download the library: Download fudge/silex-container-aware 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/ */

    

fudge / silex-container-aware example snippets




ilex\Application;
use Silex\Provider\ServiceControllerServiceProvider;
use Fudge\SilexComponents\ContainerAware\ContainerAwareServiceProvider;

$app = new Application;
$app->register(new ContainerAwareServiceProvider);
$app->register(new ServiceControllerServiceProvider);
$app->get("/", "IndexController::hello");



class IndexController extends \Fudge\SilexComponents\ContainerAware\Controller
{
    public function hello()
    {
        return $this->render("foo.html.twig");
    }

    protected function render($templateName)
    {
        return $this->get("twig")->render($templateName);
    }

    protected function get($service)
    {
        return $this->getContainer()[$service];
    }
}