简体   繁体   中英

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. 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

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.

$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),
  );
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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