/** * Shortcut for calling a controller method and printing the result * @param string $controllerName: the name of the controller under which it is * stored in the DI container * @param string $methodName: the method that you want to call * @param array $urlParams: an array with variables extracted from the routes * @param bool $disableAdminCheck: disables the check for adminuser rights * @param bool $isAjax: if the request is an ajax request */ function callController($controllerName, $methodName, $urlParams, $disableAdminCheck = true, $isAjax = false) { $container = createDIContainer(); // run security checks $security = $container['Security']; runSecurityChecks($security, $isAjax, $disableAdminCheck); // call the controller and render the page $controller = $container[$controllerName]; $response = $controller->{$methodName}($urlParams); echo $response->render(); }
/** * Shortcut for calling a controller method and printing the result * @param string $controllerName: the name of the controller under which it is * stored in the DI container * @param string $methodName: the method that you want to call * @param array $urlParams: an array with variables extracted from the routes * @param Pimple $container: an instance of a pimple container. if not passed, a * new one will be instantiated. This can be used to * set different security values prehand or simply * swap or overwrite objects in the container. */ function callController($controllerName, $methodName, $urlParams, $container = null) { // assume a normal request and disable admin and csrf checks. To specifically // enable them, pass a container with changed security object if ($container === null) { $container = createDIContainer(); $container['Security']->setIsAdminCheck(false); $container['Security']->setCSRFCheck(false); } runSecurityChecks($container['Security']); // call the controller and render the page $controller = $container[$controllerName]; $response = $controller->{$methodName}($urlParams); echo $response->render(); }