Get route information from Zend_Controller_Request

I am trying to get routing information from a random URL (part of my application).

I tried to create an instance of Zend_Controller_Request_Http with a URL, but it did not populate the controller, module, action field automatically.

I believe that it should somehow be connected with the route information, but cannot understand how to connect it.

Any conclusions?

+3
source share
1 answer

. , route, . , match - , .

, Zend_Controller_Router_Rewrite:: route , "fudgery" ruter sbuclass elsehwere.

fudging:

// assume $router is your router instance, $request is the REAL request.

$testRequest = new Zend_Controller_Request_Http($url);

// need to use a try because if the route doesnt match youve got an exception coming
try {
  $router->route($testRequest);
} catch(Zend_Controller_Router_Exception $e) {
  $testRequest = false;
}

// revert back to the real current route which was modified during the previous call

$router->route($request);

if(false !== $testRequest) {
  // consume what you need form testRequest as you normally would
  print_r($testRequest->getParams());
}

, . , , , , route :

public function parseRoute(Zend_Controller_Request_Abstract $request)
{

   $preservedRoute = $this->_currentRoute;
   try {

      $router->route($request);
      $this->_currentRoute = $preservedRoute;

   } catch(Zend_Controller_Router_Exception $e) {

      $this->_currentRoute = $preservedRoute;
      return false;
   }

   return $request;
}

, , 1,6 1,7, , YMMV. , .

+1

Source: https://habr.com/ru/post/1759044/