繁体   English   中英

Drupal 7自定义模块给出了403

[英]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 argumentspage_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_callbackhook_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.

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