加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 在重定向symfony2之前检查url

发布时间:2020-12-13 18:13:23 所属栏目:PHP教程 来源:网络整理
导读:if ($u = $this-generateUrl('_'.$specific.'_thanks')) return $this-redirect($u);else return $this-redirect($this-generateUrl('_thanks')); 当它存在时,我不想重定向到_specific_thanks url.那么如何检查网址是否存在? 当我这样做时,我遇到了这个错误
if ($u = $this->generateUrl('_'.$specific.'_thanks'))
  return $this->redirect($u);
else
  return $this->redirect($this->generateUrl('_thanks'));

当它存在时,我不想重定向到_specific_thanks url.那么如何检查网址是否存在?

当我这样做时,我遇到了这个错误:

Route “_specific_thanks” does not exist.

我认为没有直接的方法来检查路线是否存在.但是你可以通过路由器服务寻找路由存在.
$router = $this->container->get('router');

然后,您可以获取路由集合并为给定路由调用get(),如果它不存在则返回null.

$router->getRouteCollection()->get('_'. $specific. '_thanks');

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读