如何允许除第 1 部分和第 2 部分之外的所有内容?
这使我能够轻松获得动态输入变量,而不是放置像 /en/etcetcetc 这样的静态前缀,但问题是所有控制器都被阻止。一切都转到索引/索引。
问题:我如何知道此规则允许像现在这样的一切,但不跟踪它是否包含 http://site .com/donotcatch/me 和 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_]*$',
)
);
关注上:
通常情况下,我总是相信我们可以,所以,我们可以这样做,其中动态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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嘿,现在听起来好像您只想让每个(ajax)操作执行其自己的操作。你是这个意思吗?如果是这样,我认为你可以使用这个:
你还可以为与你的正则表达式不匹配的其余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:
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?
我认为 Zend 不支持使用“否定”匹配条件。幸运的是,正则表达式使用负向先行或后向查找:
例如,以下正则表达式:
告诉正则表达式解析器排除恰好是
foo
或bar
的匹配项。fbar
、bfoo
和fbarf
仍会匹配。注意:在上面的正则表达式中,
[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:
Tells the regex parser to exclude matches that are exactly
foo
orbar
.fbar
,bfoo
andfbarf
would still be matched.Note: In your regex above,
[a-zA-Z0-9_]
is exactly the same as\w
.