1. Go to this page and download the library: Download elie29/core 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/ */
// Protect variables from global scope
return call_user_func(function () {
$config = $config));
});
chdir(dirname(__DIR__));
ta/config/container.php';
$core = new Core($container);
$core->run();
namespace Controllers;
class HomeIndexController extends AbstractController
{
public function doRun(): bool
{
$render = $this->container->get(RenderInterface::class);
// true because cache_time is not defined in config.php
return $render->hasLayoutExpired();
}
public function run(array $params = []): array
{
$render = $this->container->get(RenderInterface::class);
// global data for layout/templates
$render->assign([
'description' => 'first description',
]);
// layout specific data
return ['tplContent' => '<span>my content</span>'];
}
}
public function run(array $params = []): array
{
$render = $this->container->get(RenderInterface::class);
// global data for layout/templates
$render->assign([
'description' => 'displayed description',
]);
// layout specific data
return ['tplContent' => $this->getMyTemplate()];
}
protected function getMyTemplate(): string
{
$cacheID = sha1(__FILE__ . 'product/detail');
$cacheTime = 5; // 5 seconds in cache
$render = $this->container->get(RenderInterface::class);
// data is not needed when file is read from cache
$data = [];
// overrides keys assigned in run
$render->assign([
'description' => __METHOD__,
]);
if ($render->hasTemplateExpired($cacheID, $cacheTime)) {
$data = [
'item' => time(),
'description' => 'overriden by assign method'
];
}
// specific product/detail template under views_path
return $render->fetchTemplate($data, 'product/detail', $cacheID, $cacheTime);
}