这个问题类似于这个问题,但我不明白如何对URL进行足够的修改,以便给出对我来说有意义的答案。
默认情况下,该模块添加检索和索引操作。我试图用一个额外的选项(未读)扩展privatemsg_services_resources。
我在函数中添加了unread,如下所示,但我不知道如何通过URL访问它。
function privatemsg_services_services_resources() {
return array(
'privatemsg' => array(
'operations' => array(
'index' => array(
'callback' => '_privatemsg_services_get',
'access callback' => 'user_is_logged_in',
'args' => array(),
),
'unread' => array(
'callback' => '_privatemsg_services_unread_count',
'access callback' => 'user_is_logged_in',
'args' => array(
array(
'name' => 'uid',
'type' => 'int',
'description' => t('UID of the user to check the number of unread messages for.'),
'source' => array(
'path' => 0,
),
),
),
),
'retrieve' => array(
'callback' => '_privatemsg_services_get_thread',
'access arguments' => array(
'get private messages from remote',
),
'args' => array(
array(
'name' => 'thread_id',
'type' => 'int',
'description' => t('ID of the thread to be retrieved.'),
'source' => array(
'path' => 0,
),
),
),
),
),
),
);
}当我访问www.myexample.com/德鲁帕加普/私有网站时,我得到了索引的值。
当我进入www.myexample.com/drupalgap/privatemsg/THREAD_ID,时,我得到了THREAD_ID的检索值。
当我去www.myexample.com/drupalgap/privatemsg/unread/UID或www.myexample.com/drupalgap/privatemsg/unread,时,我会得到消息["Invalid parameters passed."]。
但是,如果我注释掉检索的函数,然后将unread重命名为检索(以测试我的代码是否未读),在清除缓存后,请访问www.myexample.com/drupalgap/私有程序/UID,给出未读消息的数量。所以代码没问题,我只是用错误的方式设置了资源。
如何从URL调用检索和未读?
发布于 2015-02-16 19:19:31
关键是在创建非CRUD资源时使用actions数组而不是operations数组。
下面是DrupalGap的一个示例:http://drupalgap.org/node/187
在使用POST时,所有调用都必须使用actions。
当使用operations时,调用是基于HTTP方法(GET、POST、PUT、DELETE)定向的。
不要忘记将X-CSRF-Token头附加到POST调用。它的值可以在这里检索:?q=services/session/token
由于这是针对DrupalGap的,而且您正在将一个参数传递给您的服务资源,因此我建议按照以下说明,这样就可以使用jDrupal并轻松地重用您的函数(S):
http://drupalgap.org/node/203
https://drupal.stackexchange.com/questions/147091
复制相似问题