What does the $basepath
refers in twig extension and str_replace
function is used here
// Instantiate and add Slim specific extension
$basePath = rtrim(str_ireplace('index.php', '', $container->get('request')->getUri()->getBasePath()), '/');
$view->addExtension(new Slim\Views\TwigExtension($container->get('router'), $basePath));
return $view;
}
This Twig extension adds some useful twig functions (see github), it depends on Base Path parameter.
Base Path
If your Slim application's front-controller lives in a physical subdirectory beneath your document root directory, you can fetch the HTTP request's physical base path (relative to the document root) with the Uri object's getBasePath() method. This will be an empty string if the Slim application is installed in the document root's top-most directory.
str_ireplace()
is used to just remove index.php