Drupal 7 菜单但没有 clean-urls
我正在开发一个模块,该模块需要对同一模块定义的菜单路径进行ajax 调用。
下面是 hook_menu 函数:
function staff_filter_menu(){
return $items['staff/filtering/results'] = array(
'page callback' => 'staff_filter_function',
'type' => MENU_CALLBACK,
);
}
function staff_filter_function(){
drupal_json( array('status' => 0, 'data' => "staff_filter_function RESPONDING!"));
}
和 js 代码:
(function($){
$(document).ready(
function(){
$results = $.get('http://localhost/test1.localhost/?q=staff/filtering/results');
//$results = $.get('http://localhost/test1.localhost/?q=admin/config/people');
//$results = $.get('http://localhost/test1.localhost/admin/config/people');
});
})(jQuery);
第一行(对我定义的菜单的调用)失败并在 firebug 中返回 404 错误。
因此,我尝试了现有的随机菜单,即以下 2 个菜单。但我做了一个使用干净的 URL 的工作,而另一个则没有。具有干净 URL 的现有菜单集也失败了,但不是干净 URL 的同一菜单工作正常。
因为无论我尝试什么,我的本地主机安装都不愿意使用干净的 URL,所以我需要一种技术来使我的模块灵活,无论站点是否使用干净的 URL 工作(特别是如果我最终发布它) )。
I am in the process of developing a module which needs to make an ajax call to a menu path defined by the same module.
Below is the hook_menu function:
function staff_filter_menu(){
return $items['staff/filtering/results'] = array(
'page callback' => 'staff_filter_function',
'type' => MENU_CALLBACK,
);
}
function staff_filter_function(){
drupal_json( array('status' => 0, 'data' => "staff_filter_function RESPONDING!"));
}
And the js code:
(function($){
$(document).ready(
function(){
$results = $.get('http://localhost/test1.localhost/?q=staff/filtering/results');
//$results = $.get('http://localhost/test1.localhost/?q=admin/config/people');
//$results = $.get('http://localhost/test1.localhost/admin/config/people');
});
})(jQuery);
The first line (the call to my defined menu) fails and returns a 404 error in firebug.
So, I tried an existing random menu which are the 2 following menus. But I made one work with clean URLs and the other without. The existing menu set with a clean URLs also failed but the same menu which isn't a clean URL worked fine.
Because my localhost installation is not happy to work with clean URLs regardless of what I try, I need a technique to make my module flexible regardless of if the site is working with or without clean URLs (particularly if I end up releasing it).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 Drupal 函数 URL。如果清理 URL 打开或关闭,这将相应调整。
例如:
则返回
如果 clean URL 关闭,
?q=NODE_ALIAS
;如果打开,则返回
NODE_ALIAS
。这为我省去了很多麻烦,因为我的本地主机也有类似的问题。有关 URL 函数的更多信息 - http://api .drupal.org/api/drupal/includes%21common.inc/function/url/7
You can use the Drupal function URL. This will adjust accordingly if clean URL's are on or off.
For example:
Will return either:
?q=NODE_ALIAS
if clean URL's is offOR
NODE_ALIAS
if they are turned on.This has saved me loads of hassle as I have a similar issue with my localhost. For more info on the URL function - http://api.drupal.org/api/drupal/includes%21common.inc/function/url/7