[英]Drupal 7 custom module gives 403
我在自定义drupal 7模块上遇到了一些麻烦。 请注意,这不是我的第一个模块。 这是我的hook_menu;
function blog_contact_menu(){
$items = array();
$items["blog_contact/send_to_one"] = array(
"page_callback"=>"single_blogger_contact",
"access_arguments"=>array("access blog_contact content"),
"type"=>MENU_CALLBACK
);
return $items;
}
这是我的烫发功能;
function blog_contact_perm() {
return array("access blog_contact content");
}
这应该工作但是当我做一个ajax调用时,它会禁止403。 您无权查看bla bla。 我的ajax调用是正确和简单的,url是正确的,类型是post。 我没有直接看到原因。
菜单路由器项目中的属性中包含空格而不是下划线。 access_arguments
实际上应该是access arguments
, page_arguments
应该是page arguments
等:
function blog_contact_menu(){
$items = array();
$items["blog_contact/send_to_one"] = array(
"title" => "Title",
"page callback"=>"single_blogger_contact",
"access arguments"=>array("access blog_contact content"),
"type"=>MENU_CALLBACK
);
return $items;
}
另请注意, title
是必需的属性。
除此之外,已经提到过hook_permission()
问题,你的代码就是现货。
既然你没有指定access_callback
在hook_menu
实现,它使用的是user_access
默认功能和检查,看看是否有access blog_contact content
的许可授权。
function blog_contact_menu(){
$items = array();
$items["blog_contact/send_to_one"] = array(
// As mentioned in Clive's answer, you should provide a title
"title" => "Your Title goes here",
"page callback"=>"single_blogger_contact",
// No "access callback" so uses user_access function by default
"access arguments"=>array("access blog_contact content"),
"type"=>MENU_CALLBACK
);
access blog_contact content
不是Drupal知道的权限,因此user_access
函数返回false,这就是您获得403访问被拒绝的原因。
如果你想告诉Drupal access blog_contact content
权限,那么钩子是hook_permission
,而不是hook_perm
。
你的代码应该更像:
function blog_contact_permission() {
return array(
'access blog_contact content' => array(
'title' => t('Access blog_contact content'),
'description' => t('Enter your description here.'),
),
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.