Example #1
0
 public function __construct($options = null)
 {
     if (NULL === $options) {
         return;
     }
     if ($options instanceof Zend_Config) {
         $options = $options->toArray();
     }
     // Explode MCA configuration
     if (!empty($options['mca'])) {
         $opts = array();
         // Parse the 'url' to extract the path and the query string
         $info = parse_url($options['mca']);
         // Uri prefixed with a name and followed by ':' define the route name
         if (empty($options['route']) && !empty($info['scheme'])) {
             $options['route'] = $info['scheme'];
         }
         // If the path shortcut is present process it
         if (isset($info['path'])) {
             $mca = explode('/', $info['path']);
             $options['module'] = empty($mca[0]) ? null : $mca[0];
             $options['controller'] = empty($mca[1]) ? null : $mca[1];
             $options['action'] = empty($mca[2]) ? null : $mca[2];
         }
         // Parse the query string
         if (isset($info['query'])) {
             parse_str($info['query'], $args);
             // Finally merge the module, controller, action with the args
             $options['params'] = isset($options['params']) ? $options['params'] : array();
             $options['params'] = array_merge($args, $options['params']);
         }
         // Check if the anchor is supplied in the URL
         if (empty($options['anchor']) && isset($info['fragment'])) {
             $options['anchor'] = $info['fragment'];
         }
     }
     // Explore ACL configuration
     if (!empty($options['acl'])) {
         $parts = explode('/', $options['acl']);
         if (count($parts) === 2) {
             $options['resource'] = empty($parts[0]) ? null : $parts[0];
             $options['privilege'] = empty($parts[1]) ? null : $parts[1];
         }
     }
     // ZF routing mechanism has a very nasty behaviour when using it to
     // create navigational links. It will use the last matched route to
     // assemble new urls without a specific route, generating weird urls
     // or even failing to generate one.
     // As a work around, any page which doesn't have an associated route,
     // gets automatically assigned the "default" one.
     //
     // bug: http://framework.zend.com/issues/browse/ZF-6733
     //
     if (!isset($options['route'])) {
         $options['route'] = 'default';
     }
     parent::__construct($options);
 }
Example #2
0
 public function __construct(array $options)
 {
     if (!isset($options['route']) || empty($options['route'])) {
         throw new Zend_Controller_Router_Exception('No routename specified!');
     }
     $front = Zend_Controller_Front::getInstance();
     $router = $front->getRouter();
     $route = $router->getRoute($options['route']);
     $defaults = $route->getDefaults();
     $options['module'] = $defaults['module'];
     $options['controller'] = $defaults['controller'];
     $options['action'] = $defaults['action'];
     parent::__construct($options);
 }