Php Drupal 7无法识别自定义模块中的Twilio客户端

Php Drupal 7无法识别自定义模块中的Twilio客户端,php,drupal,foreach,submit,twilio,Php,Drupal,Foreach,Submit,Twilio,我有一个Twilio帐户,我正在为我的Drupal站点编写一个大众短信模块。在模块开始时,我使用以下代码设置了Twilio客户端: $path = drupal_get_path("library", "twilio"); require($path . "twilio/Services/Twilio.php"); $accountSID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"; $authToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";

我有一个Twilio帐户,我正在为我的Drupal站点编写一个大众短信模块。在模块开始时,我使用以下代码设置了Twilio客户端:

$path = drupal_get_path("library", "twilio");
require($path . "twilio/Services/Twilio.php");
$accountSID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$authToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$client = new Services_Twilio($accountSID, $authToken);
$from = "xxxxxxxxxx";
myModule_submit()查询数据库中的电话号码,并通过上面提到的Twilio PHP库将其发送出去。我正在使用Twilio网站上的代码来实现类似的功能(http://www.twilio.com/docs/howto/sms-notifications-and-alerts). 问题是,当我填写要发送的短信的表单并按submit时,我会收到以下错误消息:

注意:未定义变量:myModule_submit()中的客户端(第128行/var/www/erosas/anysite.com/sites/all/modules/myModule/myModule.module)。 注意:正在尝试获取myModule_submit()中非对象的属性(第128行/var/www/erosas/anysite.com/sites/all/modules/myModule/myModule.module)。 注意:正在尝试获取myModule_submit()中非对象的属性(第128行/var/www/erosas/anysite.com/sites/all/modules/myModule/myModule.module)。

提交功能是:

function myModule_submit($form, &$form_state){

// Retrieve the values from the fields of the custom form
$values = $form_state['values'];


// Use Database API to retrieve current posts.
$query = db_select('field_data_field_phone_number', 'n');
$query->fields('n', array('field_phone_number_value'));

// Place queried data into an array
$phone_numbers = $query->execute();

$body = $values['sms_message'];

// Iterate over array and send SMS 
foreach($phone_numbers as $number){
    $client->account->sms_messages->create($from, $number, $body); // This is line 128
}
}


如果您有任何想法/帮助,我将不胜感激,我尝试搜索此网站和谷歌以获得答案,但没有找到任何特定于Drupal的答案。

$client object对submit函数不适用。尝试输入相同的代码

$path = drupal_get_path("library", "twilio");
require($path . "twilio/Services/Twilio.php");
$accountSID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$authToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$client = new Services_Twilio($accountSID, $authToken);
$from = "xxxxxxxxxx";
在提交函数的开头

   function pulsesurf_submit($form, &$form_state){
     $path = drupal_get_path("library", "twilio");
     require($path . "twilio/Services/Twilio.php");
     $accountSID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
     $authToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
     $client = new Services_Twilio($accountSID, $authToken);
     $from = "xxxxxxxxxx";

    // Retrieve the values from the fields of the custom form
    $values = $form_state['values'];


    // Use Database API to retrieve current posts.
    $query = db_select('field_data_field_phone_number', 'n');
    $query->fields('n', array('field_phone_number_value'));

    // Place queried data into an array
    $phone_numbers = $query->execute();

    $body = $values['sms_message'];

    // Iterate over array and send SMS 
    foreach($phone_numbers as $number){
        $client->account->sms_messages->create($from, $number, $body); // This is line 128
    }
...
为了便于使用,最好使一些不带参数的include函数只包含库文件并设置令牌/sid


顺便说一句,错误消息中显示了您站点的域

谢谢!我不再收到错误消息,但它会重定向到用户帐户页面,而不会确认正在发送的消息。我尝试使用drupal\u set\u message(),但这不起作用。有什么建议吗?您在提交函数中使用drupal_goto()吗?除非重写,否则不应将用户重定向到用户页。drupal_设置_message()在drupal_goto()对我大多数时间起作用之前。不,我没有使用drupal_goto(),似乎代码的查询部分有问题,当我在sms_messages->create()参数中以字符串形式输入电话号码,而不是$to时,它会起作用,否则它会重定向到用户页面。