Ejemplo n.º 1
0
 public function addRoutes(Zend_Controller_Router_Interface $router)
 {
     $frontName = $this->_config->getName();
     $routeMatch = $frontName . '/:controller/:action/*';
     $moduleName = (string) $this->_config->module;
     $routeParams = array('module' => $moduleName, 'controller' => 'index', 'action' => 'index', '_frontName' => $frontName);
     $route = new Zend_Controller_Router_Route($routeMatch, $routeParams);
     $router->addRoute($moduleName, $route);
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * Sets all the default routes for processing the friendly URLs
  *
  * @param Zend_Controller_Router_Interface $router
  */
 public static function setDefaultRoutes(Zend_Controller_Router_Interface $router)
 {
     $internalUrl = 'sydney\\/|publicms|admin|default\\/';
     // routeName => array( route, defaults, map, reverse )
     $routesRegex = array('searchRoute' => array('search\\.html', array('module' => 'publicms', 'controller' => 'search', 'action' => 'index'), null, 'search.html'), 'fileRoute' => array('(.*)FILE-([0-9]*)', array('module' => 'publicms', 'controller' => 'file', 'action' => 'getrfile'), array(1 => 'slug', 2 => 'id'), '%sFILE-%s%s'), 'filedisplayedRoute' => array('sydney\\/img\\/([0-9]{1,4})-([0-9]{1,10})\\.(png|jpg|gif)', array('module' => 'publicms', 'controller' => 'file', 'action' => 'showimg'), array(1 => 'dw', 2 => 'id', 3 => 'ext'), 'sydney/img/%s-%s.%s'), 'pageRoute' => array('^((?!' . $internalUrl . ').*)$', array('module' => 'publicms', 'controller' => 'index', 'action' => 'view'), array(1 => 'slug'), '%s'));
     foreach ($routesRegex as $k => $v) {
         $router->addRoute($k, new Zend_Controller_Router_Route_Regex($v[0], $v[1], $v[2], $v[3]));
     }
     $router->addRoute('sydneydefault', new Zend_Controller_Router_Route('', array('module' => 'publicms', 'controller' => 'index', 'action' => 'view')));
 }
Ejemplo n.º 3
0
 /**
  * Delete Action
  *
  * @return void
  */
 public function deleteAction()
 {
     $id = $this->_getParam('id');
     $this->view->headTitle()->prepend('Delete');
     $entry = $this->_entryMapper->getEntry($id);
     if (null === $entry) {
         throw new Zend_Controller_Dispatcher_Exception();
     }
     $this->_entryMapper->deleteEntry($entry);
     $this->_redirect($this->_router->assemble(array('action' => 'index', 'controller' => 'entry'), null, true));
 }
Ejemplo n.º 4
0
 /**
  * Create HTML markup for request debugging.
  * 
  * @param Zend_Controller_Request_Abstract $request Request object.
  * @param Zend_Controller_Router_Interface $router Router object.
  * @return string HTML markup.
  */
 private function _getRequestMarkup($request, $router)
 {
     $requestUri = $request->getRequestUri();
     $html = "<h2>Request Data</h2>\n\n<div>Request URI: <em>{$requestUri}</em>" . "</div>\n<div>Params:";
     $reqParams = $request->getParams();
     // Rendering the whole error_handler ArrayObject is annoying and causes
     // errors when request params are later used to assemble routes.
     if (array_key_exists('error_handler', $reqParams)) {
         $errHandler = $reqParams['error_handler'];
         $reqParams['exception'] = (string) $errHandler['exception'];
         $reqParams['exception_type'] = $errHandler['type'];
         unset($reqParams['error_handler']);
     }
     $html .= '<pre>' . print_r($reqParams, true) . '</pre>';
     $html .= "</div>";
     if ($request->isPost()) {
         $html .= "<h2>Post Data</h2>";
         $html .= '<pre>' . print_r($_POST, true) . '</pre>';
     }
     $html .= "<h2>Session Data</h2>";
     $html .= '<pre>' . print_r($_SESSION, true) . '</pre>';
     $html .= "<h2>Server Data</h2>";
     $html .= '<pre>' . print_r($_SERVER, true) . '</pre>';
     $currentRoute = $router->getCurrentRouteName();
     $routes = $router->getRoutes();
     $html .= "<h2>Routing Data</h2>";
     $html .= "<div>Current Route: <strong>{$currentRoute}</strong></div>";
     $html .= "<div>Defined routes:\n\n";
     $html .= "<table><tr><th>Route Name</th><th>Matches Current Request</th><th>Assembled with current params</th></tr>";
     foreach ($routes as $routeName => $route) {
         try {
             $assembledRoute = $route->assemble($reqParams, true, true);
         } catch (Exception $e) {
             $assembledRoute = "Could not assemble: " . $e->getMessage();
         }
         if ($route instanceof Zend_Controller_Router_Route_Chain) {
             $routeIsMatched = $route->match($request);
         } else {
             $routeIsMatched = $route->match($request->getPathInfo());
         }
         $html .= "<tr><td>{$routeName}</td><td>" . ($routeIsMatched ? 'true' : 'false') . "</td><td>{$assembledRoute}</td></tr>";
     }
     $html .= "</table>";
     $html .= "<h2>Cookie Data</h2>";
     $html .= '<pre>' . print_r($_COOKIE, true) . '</pre>';
     return $html;
 }
Ejemplo n.º 5
0
 /**
  * Assembles a URL based on a given route
  *
  * This method will typically be used for more complex operations, as it
  * ties into the route objects registered with the router.
  *
  * @param  array   $urlOptions
  * @param  mixed   $name
  * @param  boolean $reset
  * @param  boolean $encode
  * @return string Url for the link href attribute.
  */
 public function url($urlOptions = array(), $name = null, $reset = false, $encode = true)
 {
     return $this->_router->assemble($urlOptions, $name, $reset, $encode);
 }