0

我正在尝试在 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

请让我知道我在哪里做错了。提前致谢。

4

1 回答 1

0

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

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

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

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

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

也使用源路径作为源

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

我认为源param仅适用于index操作而不是检索

于 2017-05-31T17:05:04.680 回答