Example #1
0
 public function make()
 {
     //first of all, we check for optional parameters. If they exist,
     //we will make another route without the optional parameter
     foreach ($this->optional_parameters as $parameter) {
         $from = $this->pre_from;
         //we get rid of prefix in case it exists
         if (!empty($this->prefix) && strpos($from, $this->prefix) === 0) {
             $from = substr($from, strlen($this->prefix));
         }
         foreach ($parameter as $p) {
             $from = str_replace('/{' . $p . '}', '', $from);
         }
         //save the optional routes in case we will need them for where callings
         $this->optional_objects[] = Route::createRoute($from, $this->to, $this->options, $this->nested);
     }
     // Do we have a nested function?
     if ($this->nested && is_callable($this->nested)) {
         $name = rtrim($this->pre_from, '/');
         if (array_key_exists('subdomain', $this->options)) {
             Route::prefix(array('name' => $name, 'subdomain' => $this->options['subdomain']), $this->nested);
         } else {
             Route::prefix($name, $this->nested);
         }
     }
 }
Example #2
0
 public function make()
 {
     // Due to bug stated in https://github.com/Patroklo/codeigniter-static-laravel-routes/issues/11
     // we will make a cleanup of the parameters not used in the optional cases
     $parameter_positions = array_flip(array_keys($this->parameters));
     //first of all, we check for optional parameters. If they exist,
     //we will make another route without the optional parameter
     foreach ($this->optional_parameters as $parameter) {
         $from = $this->pre_from;
         $to = $this->to;
         //we get rid of prefix in case it exists
         if (!empty($this->prefix) && strpos($from, $this->prefix) === 0) {
             $from = substr($from, strlen($this->prefix));
         }
         foreach ($parameter as $p) {
             // Create the new $from without some of the optional routes
             $from = str_replace('/{' . $p . '}', '', $from);
             // Create the new $to without some of the optional destiny routes
             if (array_key_exists($p, $parameter_positions)) {
                 $to = str_replace('/$' . ($parameter_positions[$p] + 1), '', $to);
             }
         }
         // Save the optional routes in case we will need them for where callings
         $this->optional_objects[] = Route::createRoute($from, $to, $this->options, $this->nested);
     }
     // Do we have a nested function?
     if ($this->nested && is_callable($this->nested)) {
         $name = rtrim($this->pre_from, '/');
         if (array_key_exists('subdomain', $this->options)) {
             Route::prefix(array('name' => $name, 'subdomain' => $this->options['subdomain']), $this->nested);
         } else {
             Route::prefix($name, $this->nested);
         }
     }
 }
Example #3
0
 public static function createUrl($_url)
 {
     $routes = self::getRoute();
     $route = new Route($routes);
     $url = $_url;
     $param_key = array();
     if (self::getUrlFormat() == 'get' || $routes !== null) {
         $param = '';
         if (strpos($url, '?') !== false) {
             $url_arr = explode('?', $url);
             $url = $url_arr[0];
             $param = $url_arr[1];
         }
         $param_arr = array();
         if (substr($url, 0, 1) == '/') {
             $tem = explode('/', substr($url, 1));
             $param_arr['con'] = isset($tem[0]) ? $tem[0] : null;
             $param_arr['act'] = isset($tem[1]) ? $tem[1] : null;
             $len = count($tem);
             if ($len > 2) {
                 for ($i = 2; $i < $len; $i = $i + 2) {
                     $param_arr[$tem[$i]] = isset($tem[$i + 1]) ? $tem[$i + 1] : null;
                     $param_key[$tem[$i]] = $tem[$i];
                 }
             }
         } else {
             $tem = explode('/', $url);
             $len = count($tem);
             if ($len > 0) {
                 for ($i = 0; $i < $len; $i = $i + 2) {
                     $param_arr[$tem[$i]] = isset($tem[$i + 1]) ? $tem[$i + 1] : null;
                 }
             }
         }
         if ($param != '') {
             $args = explode('&', $param);
             foreach ($args as $arg) {
                 $tem = explode('=', $arg);
                 $param_arr[$tem[0]] = $tem[1];
             }
         }
         //$param_arr = array_merge($param_arr,$param);
         if (self::getUrlFormat() == 'get') {
             $url = '?' . http_build_query($param_arr);
         } else {
             $param_key = implode("/", $param_key);
             $url = $route->createRoute($param_arr, $param_key);
             if ($url !== null) {
                 if (stripos($url, '?') !== false) {
                     $url .= $param == '' ? '' : '&' . $param;
                 } else {
                     $url .= $param == '' ? '' : '?' . $param;
                 }
             } else {
                 if (isset($param_arr['con']) && isset($param_arr['act'])) {
                     $_url = "/" . $param_arr['con'] . "/" . $param_arr['act'];
                     unset($param_arr['con'], $param_arr['act']);
                     foreach ($param_arr as $key => $value) {
                         $_url .= '/' . $key . '/' . $value;
                     }
                 }
                 return $_url;
             }
         }
     }
     return $url;
 }
Example #4
0
 public function action_create()
 {
     RoutingEngine::setPage("runnDAILY Routes", "PV__300");
     $route = new Route($_POST);
     if ($route->id) {
         if ($route->updateRoute()) {
             Notification::add("Route - {$route->name} - was updated.");
             Page::redirect("/routes/view/{$route->id}/{$route->name}");
         }
     } else {
         if ($route->createRoute()) {
             Notification::add("Route - {$route->name} - was created.");
             Page::redirect("/routes/view/{$route->id}/{$route->name}");
         }
     }
 }