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); } } }
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); } } }
/** * @param string $verb * @param Route $route * @param string $name * @return Route */ public function map($verb, Route $route, $name = null) { $route->allow($verb); if ($this->prefix !== '/') { $route->prefix($this->prefix); } if ($name == null) { $this->routes[] = $route; } else { $this->routes[$name] = $route; } return $route; }
/** * Add a prefix to the $from portion of the route. This is handy for * grouping items under a similar URL, like: * * Route::prefix('admin', function() * { * Route::resources('users'); * }); * * @param string $name The prefix to add to the routes. * @param Closure $callback */ public static function prefix($name, Closure $callback) { self::$prefix = $name; call_user_func($callback); self::$prefix = null; }
| When you set this option to TRUE, it will replace ALL dashes in the | controller and method URI segments. | | Examples: my-controller/index -> my_controller/index | my-controller/my-method -> my_controller/my_method */ $route['default_controller'] = 'home'; $route['404_override'] = ''; // Authentication Route::any(LOGIN_URL, 'users/login', array('as' => 'login')); Route::any(REGISTER_URL, 'users/register', array('as' => 'register')); Route::block('users/login'); Route::block('users/register'); Route::any('logout', 'users/logout'); Route::any('forgot_password', 'users/forgot_password'); Route::any('reset_password/(:any)/(:any)', 'users/reset_password/$1/$2'); // Activation Route::any('activate', 'users/activate'); Route::any('activate/(:any)', 'users/activate/$1'); Route::any('resend_activation', 'users/resend_activation'); // Contexts Route::prefix(SITE_AREA, function () { Route::context('content', array('home' => SITE_AREA . '/content/index')); Route::context('reports', array('home' => SITE_AREA . '/reports/index')); Route::context('developer'); Route::context('settings'); }); $route = Route::map($route); if (defined(CI_VERSION) && substr(CI_VERSION, 0, 1) != '2') { $route['translate_uri_dashes'] = false; }