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