Php 创建Drupal服务模块?
目前,我正试图用一个flash客户端连接一个定制的Drupal7服务模块。我可以正确连接到amfserver服务,并实际使用节点服务抓取和操作节点。我正在尝试构建一个自定义服务,以远程提供可用服务未提供的功能。我正在尝试建立一个简单的框架,以便在我的服务模块和服务器之间进行通信。我有很多问题,因为我不知道如何正确地构建一个服务,而且我能找到的大部分信息都不能很好地工作。目前,我可以确认我的flash应用程序正在连接模块,但模块返回NULL。我想这可能很简单,但我对php和DrupalAPI不太熟悉,所以任何帮助都很好。下面是我目前拥有的模块代码Php 创建Drupal服务模块?,php,flash,actionscript-3,drupal-7,drupal-modules,Php,Flash,Actionscript 3,Drupal 7,Drupal Modules,目前,我正试图用一个flash客户端连接一个定制的Drupal7服务模块。我可以正确连接到amfserver服务,并实际使用节点服务抓取和操作节点。我正在尝试构建一个自定义服务,以远程提供可用服务未提供的功能。我正在尝试建立一个简单的框架,以便在我的服务模块和服务器之间进行通信。我有很多问题,因为我不知道如何正确地构建一个服务,而且我能找到的大部分信息都不能很好地工作。目前,我可以确认我的flash应用程序正在连接模块,但模块返回NULL。我想这可能很简单,但我对php和DrupalAPI不太熟
<?php
// mrbremoteresource.module
/**
* Implements hook_perm().
*/
function mrbremoteresourse_perm() {
return array(
'mrbremote resource search',
);
}
/**
* Perform a search node ID.
*
* @param string $id
* Node ID to lookup
* @return object
*/
function mrbremoteresource_search($id) {
$nodes = array();
$result = db_query("SELECT title FROM {node} WHERE nid=:id", array(':id' => $id));
$res = $result->fetchObject();
foreach ($res as $node) {
$nodes[] = $node;
}
return $nodes;
}
/**
* Implements hook_services_resources().
*/
function mrbremoteresource_services_resources() {
return array(
'mrbremote' => array(
'search' => array(
'help' => 'Retrieve a node',
'file' => array('file' => 'inc', 'module' => 'mrbremoteresource'),
'callback' => '_mrbremoteresource_find',
'access callback' => '_mrbremoteresource_access',
'access arguments' => array('view'),
'access arguments append' => TRUE,
'args' => array(
array(
'name' => 'id',
'type' => 'int',
'description' => 'The id of the node to get',
'source' => array('path' => '0'),
'optional' => FALSE,
),
),
),
),
);
}
/**
* Access callback for the node resource.
*
* @param string $op
* The operation that's going to be performed.
* @param array $args
* The arguments that will be passed to the callback.
* @return bool
* Whether access is given or not.
*/
function _mrbremoteresource_access($op, $args) {
global $user;
$access = FALSE;
switch ($op) {
case 'view':
$node = mrbremoteresource_search($args[0]);
$access = user_access('this resource view any node');
$access = $access || $note->uid == $user->uid && user_access('this resource view own nodes');
break;
}
// Force access for debugging
$access = TRUE;
return $access;
}?>
<?php
// noteresource.inc
/**
* Callback for retrieving note resources.
*
* @param string $id
* Node ID to lookup
* @return object
*/
function _mrbremoteresource_find($id) {
return mrbremoteresoure_search($id);
}
?>
我曾试图利用来自的信息来实现这一点,但迄今为止都没有成功。让它工作的最好方法是什么
编辑:我从一个简单的flash客户端添加代码。实际上,我正试图将它用于另一个应用程序,但我只是将这个小应用程序扔在一起,以便可以调试它
<?xml version="1.0" encoding="utf-8"?.>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
initialize="init();">
<fx:Script>
<![CDATA[
public function init():void {
remNode.search("1")
}
public function onResult(responds:Object):void {
trace(responds);
}
public function onFault(responds:Object):void {
trace(responds);
}
]]>
</fx:Script>
<fx:Declarations>
<s:RemoteObject endpoint="http://localhost/drupal/remmirecipebox"
destination="amfserver"
source="mrbremote"
id="remNode"
showBusyCursor="true">
<s:method name="search" result="onResult(event)" fault="onFault(event)"/>
</s:RemoteObject>
</fx:Declarations> </s:Application>
在顶部的xml标记中,我只添加了一个。在两人之间?因为它不断删掉我的代码。它不在实际的应用程序代码中。关于您的“服务”的信息确实不够。它应该返回什么?什么格式。。现在您只需返回一个PHP数组,它通常转换为一个数组字符串。您是否在浏览器中手动调出该页面?您可能应该解释flash正在阅读的浏览器页面中当前显示的内容,以及您希望flash看到的内容。事实上,并不是所有的都在一段中=D。我现在只是在我的flash调试器中获取结果事件,因为这是我已经在使用的,我实际上不会将该服务用于端点以外的任何东西。在我的flash客户端上,我可以远程调用node.retrieve,并在结果中获得一个数组。对于我的模块。。。我得到NULL,即使它似乎应该返回一个数组。在这种情况下,我假设返回一个数组应该可以工作。我使用Drupal7,amfserver模块进行设置,我使用flash应用程序作为通过remoteObject连接的客户端。