url 中的区域设置模块和语言前缀
我一直在研究模块,并且很清楚 hook_menu 用于传递 url 参数进行回调。例如:
$items['webtv/block/%/playlist/edit/%'] = array(
...
'page callback' => 'drupal_get_form',
'page arguments' => array('webtv_playlist_form', 5, 2),
...
);
和回调 as
function webtv_playlist_form($form_state, $fifth_arg, $second_arg){
...
}
除了 arg() 函数之外,还有另一个实用程序可以通过位置获取 url 参数。
$second_arg = arg(2);
$fifth_arg = arg(5);
当我启用区域设置模块以使 Web 成为多语言时,URL 会使用前缀作为语言符号进行分类。示例:
en/webtv/block/%/playlist/edit/%
OR
nl/webtv/block/%/playlist/edit/%
这个东西将参数的逻辑位置移至右侧,现在参数的正确位置(根据示例)是:
$second_arg = arg(3);
$fifth_arg = arg(6);
如何设置独立于此类参数位置问题的模块?
I had been working on module and well aware of hook_menu for passing url arguments to call back. For instance:
$items['webtv/block/%/playlist/edit/%'] = array(
...
'page callback' => 'drupal_get_form',
'page arguments' => array('webtv_playlist_form', 5, 2),
...
);
and callback as
function webtv_playlist_form($form_state, $fifth_arg, $second_arg){
...
}
Beside that arg() function is another utility to get url arguments by their positions.
$second_arg = arg(2);
$fifth_arg = arg(5);
When I enable locale module to make web as multilingual, URLs are classified with prefix as language symbol. Example:
en/webtv/block/%/playlist/edit/%
OR
nl/webtv/block/%/playlist/edit/%
This thing displaces the logical placement of arguments to right, now the correct placement of arguments (according to example) is:
$second_arg = arg(3);
$fifth_arg = arg(6);
How to set-up module independent of such argument placement issues?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 Drupal 核心代码(例如
node_menu()
< /a>),当 locale.module 启用时,使用菜单占位符的菜单回调不会调整为工作,local.module 也不会更改从其他模块定义的菜单。事实上,
language_initialize()
,调用Drupal bootstrap 包含以下代码:该代码正在删除 URL 中传递的语言 ID。
如果 locale.module 设置正确,则在启用模块时不应更改菜单回调定义。
Looking at Drupal core code (in example,
node_menu()
), menu callback using menu placeholders are not adjusted to work when locale.module is enabled, nor local.module alters the menus defined from other modules.In fact,
language_initialize()
, called on Drupal bootstrap contains the following code:The code is removing the language ID passed in the URL.
If locale.module is correctly set, the menu callback definitions should not be changed when the module is enabled.