在drupal服务自定义资源中查询字符串

时间:2017-05-31 04:56:12

标签: web-services rest drupal drupal-7 drupal-services

我正在尝试在drupal服务API中使用查询字符串结构。它不适合我。 我也搜索了大部分解决方案,但都失败了。 这是m drupal代码:

function rapid_services_resources() {
  $resources = array(
    'get_data' => array(
      'operations' => array(
        'retrieve' => array(
          'help' => t('Gets user email of uid passed.'),
          'callback' => 'my_module_get_user_email',
          'args' => array(
                 array(
                'name' => 'nid',
                'type' => 'int',
                'description' => 'The display ID of the view to get.',
                'source' => array('param' => 'nid'),
                'optional' => TRUE,
                'default value' => 'default',
              ),
          ),
          'access arguments' => '_blog_access_provide_access',
          'access callback' => '_blog_access_provide_access',
          //~ 'access arguments append' => FALSE,
        ),
      ),
    ),
  );
  return $resources;
}

function _blog_access_provide_access() {
  return TRUE;
}

function my_module_get_user_email($nid){
    var_dump($args);die;
}

我想要这样的网址。:

http://localhost/drupaltest/rapidapi/get_data/?nid=111

请告诉我错误的地方。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

嗨,这里有参考,这将是有用的

http://pingv.com/blog/an-introduction-drupal-7-restful-services

https://www.drupal.org/node/783460

此外,我不确定查询字符串,但对于检索操作,您可以将其设置为URL的一部分 例如:

http://localhost/drupaltest/rapidapi/get_data/<nid should be here>
http://localhost/drupaltest/rapidapi/get_data/111

还使用源路径作为源

'source' => array('path' => '0'),

我认为来源param仅适用于index操作而无法检索

相关问题