PHP code example of contao-community-alliance / dependency-container
1. Go to this page and download the library: Download contao-community-alliance/dependency-container 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/ */
contao-community-alliance / dependency-container example snippets
$container['myservice.param'] = 'value';
$container['myservice'] = function($container) {
return new MyServiceClassName();
}
class MyClass
{
function myFunction()
{
global $container;
$parameter = $container['myservice.param'];
$service = $container['myservice'];
}
}
/** @var \Config $config */
$config = $container['config'];
/** @var \Environment $environment */
$environment = $container['environment'];
/** @var \Database $database */
$database = $container['database.connection'];
/** @var \Input $input */
$input = $container['input'];
/** @var \BackendUser|\FrontendUser $user */
$user = $container['user'];
/** @var \Session $session */
$session = $container['session'];
/** @var DependencyInjection\Container\PageProvider */
$pageProvider = $container['page-provider'];
$page = $pageProvider->getPage();