简体   繁体   English

与词的Drupal url通配符

[英]Drupal url wildcard with word

Is is possible to use such wildcard in menu? 可以在菜单中使用这样的通配符吗?

$items['foo/bar-%xxx']
...
'page arguments' => array(1),

So that I could get bar-something into argument? 这样我就可以讨论一下吧?

Not to make this offensive a reply, but do NOT do what danielson317 suggested. 不要让这个令人反感的回复,但不要做danielson317建议的。 The reason is that, in this way, you will have several unnecessary menu router items that gonna ruin your site performance. 原因是,通过这种方式,您将有几个不必要的菜单路由器项目,将破坏您的网站性能。 secondly, that's not how we do it usually. 其次,我们通常不会这样做。

You can do this by registering the main callback to your function. 您可以通过将主回调注册到您的函数来完成此操作。

$items['foo/%']
...
'page arguments' => array(1),

In your callback function, you can check if the given argument is valid. 在回调函数中,您可以检查给定的参数是否有效。

function MYMODULE_foo_bar($value){
if (substr($value, 0, 4) != 'bar-'){
drupal_not_found();
return; // not necessary though.
}
$value = substr($value, 5);
// $value is now the the desired value.
//do what you want and return the output.
}

According to the documentation on hook_menu http://api.drupal.org/api/drupal/developer%21hooks%21core.php/function/hook_menu/6 根据hook_menu上的文档http://api.drupal.org/api/drupal/developer%21hooks%21core.php/function/hook_menu/6

The % must be the first character of the entry. %必须是条目的第一个字符。 It can either be by itself or a string that prepends a load operator. 它可以是单独的,也可以是一个预先加载运算符的字符串。

So No You can not put an argument in that fashion. 所以不,你不能以这种方式提出论点。

You can however use a loop to create multiple entries inside of hook_menu. 但是,您可以使用循环在hook_menu中创建多个条目。

$results = some_query_function();
foreach ($results as $result) {
  $items['foo/bor-' . $result] = array();
}

And you can mix the two: 你可以将两者结合起来:

$results = some_query_function();
foreach ($results as $result) {
  $items['foo/' . $result] = array();
  $itesm['foo/bar-' . result . '/%/edit'] = array(
  ...
  'page arguments' => array(2),
  );
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM