/ A / metin maçlar Zend_Controller_Router değil / metin oluşturmak için bir yolu var mı?

1 Cevap php

Ben bir yönlendirici bir bölü çizgisi URL'leri maç ve eğik çizgi ile bu normal bir şekilde davranmasını istiyorum çalışıyorum. Ben denedim:

$route = new Zend_Controller_Router_Route(
    		':redirectid',
    		array(
    			'redirectid'	=>	false,
    			'controller'	=>	'redirect',
    			'action'	=>	'redirect'
    		),
    		array('redirectid' => '[a-z0-9]*')
    	);

ve

$route = new Zend_Controller_Router_Route_Regex(
    		'([a-z0-9]*)',
    		array(
    			'controller' => 'redirect',
    			'action'     => 'redirect'
    		)
    	);

ve both behave exactly how I want for urls without trailing slash, yet they still match for urls with a trailing slash, too. Is there any way around this?

1 Cevap

DISCLAIMER: I would highly suggest against making http://somesite.com/page and http://somesite.com/page/ being different pages- it will become confusing for you and for your visitors.

If you're truly dedicated to this plan you can create your own router you can that handles this by creating your own match() and assemble() functions that don't trim() the path based on trailing slashes.

class My_Route_Redirector implements Zend_Controller_Router_Route_Interface {
   protected $_defaults;

   public static function getInstance(Zend_Config $config) {
     $defs = ($config->defaults instanceof Zend_Config) ? $config->defaults->toArray() : array();
     return new self($defs);
   }

   public function __construct($defaults=array()) {
     $this->_defaults = $defaults;
   }

   public function match($path, $partial = false) {
     if (preg_match("#^/?([a-z0-9]+)$#i", $path, $matches)) {
       // this is just an idea but what about if you had this test
       // $matches[1] versus the database of redirectors?  and only return true
       // when it found a valid redirector?

       return array('redirectid' => $matches[1]) + $this->_defaults;
     } else {
       return false;
     }
   }

    public function assemble($data = array(), $reset = false, $encode = false, $partial = false)
    {
      if (!isset($data['redirectid'])) return '';
      return $data['redirectid'];
    }
}

Bu işe bir hata ya da iki olabilir böylece hava kodlu oldu - bu gibi çalışması gerekir:

$route = new My_Route_Redirector(
                array(
                        'controller' => 'redirect',
                        'action'     => 'redirect'
                )
        );