[英]Drupal 7 custom module gives 403
i am having some troubles with my custom drupal 7 module. 我在自定义drupal 7模块上遇到了一些麻烦。 Notice, this is not my first module. 请注意,这不是我的第一个模块。 This is my hook_menu; 这是我的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;
}
And this is my perm function; 这是我的烫发功能;
function blog_contact_perm() {
return array("access blog_contact content");
}
This should work but when i do a ajax call, it gives 403 forbidden. 这应该工作但是当我做一个ajax调用时,它会禁止403。 You are not authorized to view bla bla. 您无权查看bla bla。 My ajax call is correct and simple, the url is correct, type is post. 我的ajax调用是正确和简单的,url是正确的,类型是post。 I don't see the reason directly. 我没有直接看到原因。
Properties in menu router items have spaces in them instead of underscores. 菜单路由器项目中的属性中包含空格而不是下划线。 access_arguments
should actually be access arguments
, page_arguments
should be page arguments
, etc.: 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;
}
Also note that title
is a required property. 另请注意, title
是必需的属性。
Apart from that and the hook_permission()
problem already mentioned your code is spot on. 除此之外,已经提到过hook_permission()
问题,你的代码就是现货。
Since you didn't specify an access_callback
in your hook_menu
implementation, it is using the user_access
function by default and checking to see if you have access blog_contact content
permission granted. 既然你没有指定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
);
The access blog_contact content
is not a permission that Drupal knows about so the user_access
function returns false which is why you're getting 403 access denied. access blog_contact content
不是Drupal知道的权限,因此user_access
函数返回false,这就是您获得403访问被拒绝的原因。
If you want to tell Drupal about access blog_contact content
permission, then the hook is hook_permission
, not hook_perm
. 如果你想告诉Drupal access blog_contact content
权限,那么钩子是hook_permission
,而不是hook_perm
。
And your code should be more like: 你的代码应该更像:
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.