Пример #1
0
 public function route(Zend_Controller_Dispatcher_Interface $dispatcher)
 {
     /**
      * @todo Replace with Zend_Request object
      */
     $path = $_SERVER['REQUEST_URI'];
     if (strstr($path, '?')) {
         $path = substr($path, 0, strpos($path, '?'));
     }
     /**
      * Find the matching route
      */
     foreach ($this->_routes as $route) {
         if ($params = $route->match($path)) {
             $controller = $params['controller'];
             $action = $params['action'];
             break;
         }
     }
     $actionObj = new Zend_Controller_Dispatcher_Token($controller, $action, $params);
     if (!$dispatcher->isDispatchable($actionObj)) {
         throw new Zend_Controller_Router_Exception('Request could not be mapped to a route.');
     } else {
         return $actionObj;
     }
 }
Пример #2
0
 public function route(Zend_Controller_Dispatcher_Interface $dispatcher)
 {
     /**
      * @todo Replace with Zend_Request object
      */
     $path = $_SERVER['REQUEST_URI'];
     if (strstr($path, '?')) {
         $path = substr($path, 0, strpos($path, '?'));
     }
     $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[0];
     $action = isset($path[1]) ? $path[1] : null;
     /**
      * If no controller has been set, IndexController::index()
      * will be used.
      */
     if (!strlen($controller)) {
         $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 = 2; $i < sizeof($path); $i = $i + 2) {
         $params[$path[$i]] = isset($path[$i + 1]) ? $path[$i + 1] : null;
     }
     $actionObj = new Zend_Controller_Dispatcher_Token($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;
     }
 }
Пример #3
0
 public function route(Zend_Controller_Dispatcher_Interface $dispatcher)
 {
     /**
      * @todo Replace with Zend_Request object
      */
     $path = $_SERVER['REQUEST_URI'];
     if (strstr($path, '?')) {
         $path = substr($path, 0, strpos($path, '?'));
     }
     // Remove RewriteBase
     if (strlen($this->_rewriteBase) > 0 && strpos($path, $this->_rewriteBase) === 0) {
         $path = substr($path, strlen($this->_rewriteBase));
     }
     /**
      * Find the matching route
      */
     $controller = 'index';
     $action = 'noRoute';
     foreach (array_reverse($this->_routes) as $route) {
         if ($params = $route->match($path)) {
             $controller = $params['controller'];
             $action = $params['action'];
             $this->_currentRoute = $route;
             break;
         }
     }
     $actionObj = new Zend_Controller_Dispatcher_Token($controller, $action, $params);
     if (!$dispatcher->isDispatchable($actionObj)) {
         throw new Zend_Controller_Router_Exception('Request could not be mapped to a route.');
     } else {
         return $actionObj;
     }
 }
Пример #4
0
 public function route(Zend_Controller_Dispatcher_Interface $dispatcher, Zend_Uri_Http $url)
 {
     $params = false;
     foreach ($this->routes as $route) {
         $params = $route->isMatch($url);
         if ($params !== false) {
             break;
         }
     }
     if ($params) {
         $controller = 'index';
         $action = 'index';
         if (isset($params['controller']) && strlen($params['controller'])) {
             $controller = $params['controller'];
             if (isset($params['action'])) {
                 $action = $params['action'];
             }
         }
         unset($params['controller'], $params['action']);
         $token = new Zend_Controller_Dispatcher_Token($controller, $action, $params);
         if ($dispatcher->isDispatchable($token)) {
             return $token;
         } else {
             throw new Zend_Controller_Router_Exception('Request could not be mapped to a dispatchable route.');
         }
     } else {
         throw new Zend_Controller_Router_Exception('Request could not be mapped to a route.');
     }
 }