简体   繁体   English

对匿名用户的Drupal权限

[英]Drupal permission for anonymous user

I have create module for uploading files into database, and only administrator can upload that files. 我有用于将文件上传到数据库的创建模块,只有管理员可以上传该文件。 So I have hook_permission for administer to upload files: 所以我有hook_permission用于管理上传文件:

function upload_permission() {
  return array(
    'administer uploader' => array(
      'title' => t('Administer Uploader'),
      'description' => t('Allow the following roles to upload files files to the server.'),
    ),
  );
} 

Also I create several custom nodes with path files/node/% and now I need permission for anonymous users to see page with custom nodes. 另外,我用路径files/node/%创建了几个自定义节点,现在我需要匿名用户的权限才能查看包含自定义节点的页面。 Below I add this permission: 在下面,我添加此权限:

'access files/node/%' => array(
      'title' => t('Access Files'),
      'description' => t('Access Files.'),
    ),

and still don't work. 仍然不起作用。 Is there any other solution how anonymous user can view the page with custom nodes ? 还有其他解决方案吗?匿名用户如何使用自定义节点查看页面?

As far I know, just check the permission "view published content" in the CMS permission page that should be checked for the anonymous user role. 据我所知,只需检查CMS权限页面中的“查看已发布的内容”权限,即可检查匿名用户角色。 For viewing a Drupal node no specific permission needed until you are using any individual node permission settings. 要查看Drupal节点,无需使用特定权限,除非您使用任何单个节点权限设置。 Also, for your custom node path please use the below settings array in your hook_menu to make all path works with the URL 'files/node/%'. 另外,对于您的自定义节点路径,请在hook_menu中使用以下设置数组,以使所有路径都可以使用URL'files / node /%'。

/**
* Implements hook_menu().
*/
function yourmodule_menu() {
    $items = array();    
    $items['files/node/%'] = array(
        'title' => 'Files node',
        'page callback' => '_yourmodule_page_callback',
        'page arguments' => array(2),
        'access arguments' => array('access content'),
        'type' => MENU_CALLBACK,
      );
    return $items;
}

Just notice the below line of code, this say that anyone with the permission 'access content' (View published content) can see these node. 只需注意以下代码行,即拥有“访问内容”(查看发布的内容)权限的任何人都可以看到这些节点。

'access arguments' => array('access content'),

Hope this will help you! 希望这个能对您有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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