drupal路径别名存在与否

问题描述 投票:1回答:4

如何查找url是否存在?即导致“找不到页面”错误的网址。例如:找到测试/测试页面是否存在

我的意思是检查网站上是否确实存在给定的相对路径或完整路径,否则会导致页面未找到错误

drupal
4个回答
7
投票

您可以使用menu_valid_path()函数。返回TRUE或FALSE基于1.菜单路径是否存在以及2.当前用户是否有权查看项目。

你这样称呼它:

$item_exists = menu_valid_path(array('link_path' => $some_path));

其中$ some_path是您要测试的路径。


4
投票

如果您只想知道是否存在别名,请使用:

$path_exist = drupal_lookup_path('alias',$path);

但是,如果您想知道系统路径或别名之一是否存在,请使用:

$path_exist = drupal_lookup_path('alias',$path) || drupal_lookup_path('source',$path);

2
投票

有关Drupal 8,请参阅this URL

您可以使用:

\Drupal::service('path.alias_storage')->aliasExists('current_path', 'en')

如果系统中存在别名,它将加载“1”。


1
投票

您也可以使用请求页面:http://api.drupal.org/api/function/drupal_http_request/6 如果出错,你将得到空的$ result->错误。

© www.soinside.com 2019 - 2024. All rights reserved.