开发者

How to allow all except part 1 and part 2?

开发者 https://www.devze.com 2023-02-03 01:15 出处:网络
This allows me to get easyly dynamic input variables instead of putting a static prefix like /en/etcetcetc, but the problem is all controllers are blocked. Everything goes to index/index.

This allows me to get easyly dynamic input variables instead of putting a static prefix like /en/etcetcetc, but the problem is all controllers are blocked. Everything goes to index/index.

Question: How can i tell this rule allow evertying as it is now, but do not track if it contains http://site.com/donotcatch/me and http://site.com/iamnotbelongstodynamic1/blabla

  protected  function _initRoutes()
  { 
     ...
      $dynamic1 = new Zend_Controller_Router_Route(
            '/:variable0/:variable1',
            array(
                'controller' => 'index',
                'action'     => 'index'),
                array(
                      'variable0' => '^[a-zA-Z0-9_]*$',
                      'variable1' => '^[a-zA-Z0-9_]*$',
                    )
            );

Follow up:

Normally, i always belive yes we can, so, we can do that like this where dynamic1 does not the inter-fare with my other static controllers:

  // http://site/yeswecan/blabla
  // variable0 = yeswecan
  // variable1 = blabla
  $dynamic1 = new Zend_Controller_Router_Route(
        '/:variable0/:variable1',
        array(
            'controller' => 'index',
            'action'     => 'index'),
            array(
                  'variable0' => '^[a-zA-Z]*$',
                  'variable1' => '^[a-z0-9_]*$',
                )
        );


  // http://site/ajax/whatever...
  // solves it
  $dynamic2 = new Zend_Controller_Router_Route(
        '/ajax/:variable0',
        array(
            'controller' => 'ajax',
            'action'     => ''
            ),
            array(
                  'variable0' => '^[a-zA-Z0-9_]*$',
                )
        );

  // http://site/order/whatever...
  // solves it
  $dynamic3 = new Zend_Controller_Router_Route(
        '/order/:variable0',
        array(
            'controller' => 'order',
            'action'     => ''),
            array(
                  'variable0' => '^[a-zA-Z0-9_]*$',
                )
        ); 

Note:

  • Still the controll开发者_如何学Goers are getting failed for example http://site/ajax/whatever always goes to /ajax/index where i wanted to send it as /ajax/user-inserted-value

How can i fix the $dynamic2 and $dynamic3 by keeping $dynamic1 ??


Hey, it now sounds as if you just want each (ajax) action to go to its own action. Is that what you mean? If so, I think you can just use this:

  $dynamic2 = new Zend_Controller_Router_Route(
        '/ajax/:action',
        array(
            'controller' => 'ajax'
            ),
            array(
                  'action' => '^[a-zA-Z0-9_]*$',
                )
        );

You could also add a more general one for the rest of the ajax calls that don't match your regexp:

  $dynamic1_and_a_half = new Zend_Controller_Router_Route(
        '/ajax/:variable',
        array(
            'controller' => 'ajax',
            'action' => 'index'
            )
        );

If this is not what you mean, could you post your controllers as well, and also where you want the /ajax/whatever call to go?


I don't think Zend supports the use of "negative" matching conditions. Fortunately, regular expressions does with the use of negative lookaheads or lookbehinds:

Per example, the following regular expression:

(?!foo$|bar$)(?<!^foo|^bar)$

Tells the regex parser to exclude matches that are exactly foo or bar.

fbar, bfoo and fbarf would still be matched.

Note: In your regex above, [a-zA-Z0-9_] is exactly the same as \w.

0

精彩评论

暂无评论...
验证码 换一张
取 消