如何允许除第 1 部分和第 2 部分之外的所有内容?

发布于 2024-10-10 11:57:07 字数 2187 浏览 3 评论 0原文

这使我能够轻松获得动态输入变量,而不是放置像 /en/etcetcetc 这样的静态前缀,但问题是所有控制器都被阻止。一切都转到索引/索引。

问题:我如何知道此规则允许像现在这样的一切,但不跟踪它是否包含 http://site .com/donotcatch/mehttp://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_]*$',
                    )
            );

关注上:

通常情况下,我总是相信我们可以,所以,我们可以这样做,其中动态1不与我的其他静态控制器进行交互:

  // 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_]*$',
                )
        ); 

注意:

  • 例如,控制器仍然会出现故障 http://site/ajax/whatever 总是转到 /ajax/index 我想将其作为 /ajax 发送/user-inserted-value

我如何通过保留 $dynamic1 来修复 $dynamic2 和 $dynamic3 ?

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_]*

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]*

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

, '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:


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

, ) );

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:


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

, 'variable1' => '^[a-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 ??

, '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:


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

, ) );

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:

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

, ) ); // http://site/ajax/whatever... // solves it $dynamic2 = new Zend_Controller_Router_Route( '/ajax/:variable0', array( 'controller' => 'ajax', '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 ??

, '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:

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

, ) );

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:

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

, ) ); // 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 ??

, '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:

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

, ) );

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:

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

, ) );

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

, '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:

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

, ) );

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:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

金兰素衣 2024-10-17 11:57:07

嘿,现在听起来好像您只想让每个(ajax)操作执行其自己的操作。你是这个意思吗?如果是这样,我认为你可以使用这个:

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

你还可以为与你的正则表达式不匹配的其余ajax调用添加一个更通用的:

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

如果这不是你的意思,你也可以发布你的控制器吗?以及您希望 /ajax/whatever 调用去哪里?

, ) );

你还可以为与你的正则表达式不匹配的其余ajax调用添加一个更通用的:

如果这不是你的意思,你也可以发布你的控制器吗?以及您希望 /ajax/whatever 调用去哪里?

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?

, ) );

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

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?

明天过后 2024-10-17 11:57:07

我认为 Zend 不支持使用“否定”匹配条件。幸运的是,正则表达式使用负向先行或后向查找:

例如,以下正则表达式:

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

告诉正则表达式解析器排除恰好是 foobar 的匹配项。

fbarbfoofbarf 仍会匹配。

注意:在上面的正则表达式中,[a-zA-Z0-9_]\w 完全相同。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文