2

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 controllers 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 ??

hakre
  • 193,403
  • 52
  • 435
  • 836

2 Answers2

0

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.

netcoder
  • 66,435
  • 19
  • 125
  • 142
  • 1
    Yes, but you have static router, this is the dynamic part. And there is another flavour contain mix of both. –  Jan 04 '11 at 21:33
  • 1
    In that rule i want to say ignore anything that contain /gurunetcoder or /netcoder ex: http://site.com/netcoder/hello-globe and http://site.com/gurunetcoder/hello-globe –  Jan 04 '11 at 21:37
0

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?

Spiny Norman
  • 8,277
  • 1
  • 30
  • 55
  • 1
    But how can i do a virtual action and ignore it and keep it as :variable_reserved ? example: http://site.com/arabic/ajax/spiny-norman == http://site.com/ajax/spiny-norman ? Where :variable_reserved == arabic for later use in those controllers. –  Jan 08 '11 at 10:23
  • 1
    Well, for that you can just use your original `$dynamic2`, redirecting everything to the same action and then using `$this->getRequest()->getParam('variable0')`. So in this example you would use `'/:variable_reserved/ajax/:action'`, I guess. – Spiny Norman Jan 08 '11 at 10:27