php - Kohana:: routing with infinity params -
i want take url params in controller's action, method params (like in codeigniter). want have routing unlimited params amount (0, 5, 10 ...).
url: http://localhost/controller/action/param1/param2/..../param10...
and action be:
function action_something($param1, $param2, .... $param10) { ... }
is possible? have simple application, , want have 1 default routing every cases..
you can achieve adding "overflow" route bootstrap.php file:
route::set('default', '(<controller>(/<action>(/<overflow>)))', array('overflow' => '.*?')) ->defaults(array( 'controller' => 'api', 'action' => 'index', ));
then use kind of class access various parameters:
<?php defined('syspath') or die('no direct script access.'); class urlparam { static public function get($controller, $name) { $output = $controller->request->param($name); if ($output) return $output; $overflow = $controller->request->param("overflow"); if (!$overflow) return null; $exploded = explode("/", $overflow); ($i = 0; $i < count($exploded); $i += 2) { $n = $exploded[$i]; if ($n == $name && $i < count($exploded) - 1) return $exploded[$i + 1]; } return null; } }
usage:
then if have url such http://example.com/controller/action/param1/value1/param2/value2...
. can call controller urlparam::get($this, 'param1')
value of "param1", etc.
Comments
Post a Comment