/** * Setup ajax request on Jquery with CSRF Token */ function printAjaxHeader() { ?> <script type="text/javascript"> jQuery(function() { jQuery.ajaxSetup({ headers: { 'X-CSRF-Tiga-Token': jQuery('meta[name="_tiga_token"]').attr('content') } }); }); var tiga_ajax_url = '<?php echo tiga_url(""); ?> '; </script> <?php }
/** * Add trailing slash route or add route without trailing slash so both work * @param string $httpMethod * @param string $route * @param RouteHandler $handler */ public function addRoute($httpMethod, $route, $handler) { parent::addRoute($httpMethod, $route, $handler); // Route ended with slash , redirect non slash to slash if (substr($route, -1) === '/') { parent::addRoute($httpMethod, substr($route, 0, -1), new RouteHandler(function () { $url = tiga_url($this->request->getPathInfo() . "/"); $response = \Tiga\Framework\Response\ResponseFactory::redirect($url); $response->sendHeaders(); die; })); } else { $route .= "/"; parent::addRoute($httpMethod, $route, new RouteHandler(function () { $url = rtrim(tiga_url($this->request->getPathInfo()), '/'); $response = \Tiga\Framework\Response\ResponseFactory::redirect($url); $response->sendHeaders(); die; })); } }