【问题标题】:Phalcon route contains a wordPhalcon 路由包含一个词
【发布时间】:2017-12-21 15:08:50
【问题描述】:

我有问题。 我有路线:

$router->add('/news/{alias}(/?)', array(
'module' => 'frontend',
'controller' => 'news',
'action' => 'view',
'news_id' => 1,
'lang' => 'md',))->setName('news_view_short_e');

还有:

$router->add('/news/index/...

如果他包含“索引”,我如何检查 {alias}?

/news/{alias:(?!index)+}(/?)

不工作。 请帮忙。

我的链接:

site.com/news/index/ - 所有新闻
site.com/news/anlinter/ - 类别
site.com/news/231213-newsfriendly-url/ - 新闻视图

【问题讨论】:

  • 您能用您想要实现的示例链接更新您的问题吗?
  • 用链接更新了我的问题!
  • 你想匹配包含索引的路由还是不包含索引的路由?
  • 是的。示例:如果我访问 url site.com/news/anlinter 我得到 404 not found。如果我使用 {alias} 删除路由,我会得到正常的页面。如果他包含 (anlinter|index) ,我如何检查别名?

标签: php regex phalcon


【解决方案1】:

这个网站对理解和测试你的正则表达式很有帮助:https://regexr.com/

(?!index)+ 的正则表达式放在那里会告诉你有一个“Negative Lookahead”,它“指定一个在主表达式之后无法匹配的组(如果匹配,则丢弃结果)。”

问题在于您的?!。我在本地机器上做了一些快速测试,在那里我消除了?!,并且路由匹配正确。

【讨论】:

  • 我该如何解决?
  • /news/{alias:(index)+}(/?)
  • 没错。就像上面的用户说的:/news/{alias:(index)+}(/?)。顺便说一句,如果此答案解决了问题,请将其标记为已接受。
【解决方案2】:

测试,/news/{alias:((?!index).)+

这对我有用。

【讨论】:

猜你喜欢
  • 2017-08-18
  • 1970-01-01
  • 2013-07-02
  • 2018-06-07
  • 1970-01-01
  • 2013-07-29
  • 1970-01-01
  • 2019-06-12
  • 1970-01-01
相关资源
最近更新 更多