如何在drupal中使用通配符

发布于 2024-09-08 14:38:36 字数 528 浏览 3 评论 0原文

我有一个由 drupal 管理内容的网站,但另一个应用程序处理电子商务(我的客户不喜欢更改他自己的电子商务)

我不喜欢让电子商务看起来与其他网站不同,所以我用主体中的 php 代码创建了一个 drupal 页面节点,它只包含外部应用程序并对其进行初始化。

它运行良好,但问题是电子商务生成的另一个链接:

http://example.com/shop #The Page node i've created, this work
http://example.com/shop/catalog/fruit/ #here comes the trouble!

外部应用程序自行处理网址,所以我需要告诉 drupal 重定向所有以 shop 到他的 shop 页面节点...类似

http://example.com/shop/* => load http://example.com/shop

这样做的最佳实践是什么?

I have a website where drupal manage the contents, but another application handle the e-commerce (my customer doesnt like to change his own e-commerce)

I dont like to have the e-commerce to looks differently from the rest of the websites, so i've made a drupal Page node with php code in the body, that simply include the external app and initialize it.

It works well, but the problem is the other link the e-commerce generate:

http://example.com/shop #The Page node i've created, this work
http://example.com/shop/catalog/fruit/ #here comes the trouble!

The external app handle the url by its own, so what i need is to tell drupal to redirect all the url that begin with shop to his shop Page node... something like

http://example.com/shop/* => load http://example.com/shop

What is the best practices to do that?

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

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

发布评论

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

评论(2

萧瑟寒风 2024-09-15 14:38:37

如果您创建一个模块而不是一个节点,这将非常容易。

使用 hook_menu() 来匹配 URL 字符串

function example_menu() {
  $menu = array()
  $menu['shop'] = array(
  'page callback' = 'example_callback';
  )
}

function example_callback() {
  // use arg() to get arguments.
  return shop_php();
}

创建带有钩子菜单的回调允许您调用自己的代码,回调返回的值会显示在页面中。当 drupal 看到与 shop* 匹配的 URL 时,它将调用函数 example_callback。在此函数中,您可以将当前的代码放入页面节点中。并返回您希望在页面中显示的内容。

If you create a module rather than a node this will be quite easy.

use hook_menu() to match the URL string

function example_menu() {
  $menu = array()
  $menu['shop'] = array(
  'page callback' = 'example_callback';
  )
}

function example_callback() {
  // use arg() to get arguments.
  return shop_php();
}

Creating a callback with hook menu allows you to call your own code, the value returned by the callback will be displayed in the page. When drupal sees a URL which matches shop* it will call the function example_callback. In this function you can put the code you currently have in your page node. And return the content you wish to display in the page.

余生一个溪 2024-09-15 14:38:37

经过谷歌搜索后,我发现 Drupal custom_url_rewrite_inbound 正是我所需要的。

我将该函数插入到我的 /sites/default/settings.php 中:

function custom_url_rewrite_inbound(&$result, $path, $path_language) {
  if(preg_match("/^shop(\/)/", $path, $matches)) {
    $result = 'node/XX'; //XX is the ID of my Page Node with the ecommerce code.
  }
}

它就像一个魅力!

After googlin around, i found the Drupal custom_url_rewrite_inbound that does exactly what i need.

I inserted the function in my /sites/default/settings.php:

function custom_url_rewrite_inbound(&$result, $path, $path_language) {
  if(preg_match("/^shop(\/)/", $path, $matches)) {
    $result = 'node/XX'; //XX is the ID of my Page Node with the ecommerce code.
  }
}

It works like a charm!

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