1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
<?php
class App_Controller_Router extends Zend_Controller_Router_Abstract implements Zend_Controller_Router_Interface
{
public function route(Zend_Controller_Request_Abstract $dispatcher)
{
/**
* @todo Replace with Zend_Request object
*/
$path = $_SERVER['REQUEST_URI'];
if (strstr($path, '?')) {
$path = substr($path, 0, strpos($path, '?'));
}
//Une fois qu'on a l'url on va la chercher en DB
//print_r($path);exit;
$path = explode('/', trim($path, '/'));
/**
* The controller is always the first piece of the URI, and
* the action is always the second:
*
* http://zend.com/controller-name/action-name/
*/
$controller = $path[1];
$action = isset($path[2]) ? $path[2] : null;
/**
* If no controller has been set, IndexController::index()
* will be used.
*/
if (!strlen($controller)) {
$module = 'frontend';
$controller = 'index';
$action = 'index';
}
/**
* Any optional parameters after the action are stored in
* an array of key/value pairs:
*
* http://www.zend.com/controller-name/action-name/param-1/3/param-2/7
*
* $params = array(2) {
* ["param-1"]=> string(1) "3"
* ["param-2"]=> string(1) "7"
* }
*/
$params = array();
for ($i=3; $i<sizeof($path); $i=$i+3) {
$params[$path[$i]] = isset($path[$i+1]) ? $path[$i+1] : null;
}
$actionObj = new Zend_Controller_Dispatcher_Standard($module, $controller, $action, $params);
if (!$dispatcher->isDispatchable($actionObj)) {
/**
* @todo error handling for 404's
*/
throw new Zend_Controller_Router_Exception('Request could not be mapped to a route.');
} else {
return $actionObj;
}
}
public function assemble($userParams, $name = null, $reset = false, $encode = true)
{}
public function getFrontController()
{}
public function setFrontController(Zend_Controller_Front $controller)
{}
public function setParam($name, $value)
{}
public function setParams(array $params)
{}
public function getParam($name)
{}
public function getParams()
{}
public function clearParams($name = null)
{}
public function addRoute($name, Zend_Controller_Router_Route_Interface $route)
{}
} |
Partager