将数据传递给twlio的问题

时间:2016-08-11 04:41:13

标签: php codeigniter twilio

控制器

public function searchNew()
{


    $sid = //account_sid; 
    $token = //auth_token; 
    $client = new Services_Twilio($sid, $token);

    $country = $this->input->post('select_country');
    $type = $this->input->post('type');
    $params = array(
        'Contains' => $this->input->post('contains'),
        'SmsEnabled' => $this->input->post('SMS'),
        'MmsEnabled' => $this->input->post('MMS'),
        'VoiceEnabled' => $this->input->post('Voice'),
        'ExcludeAllAddressRequired' => TRUE,
        'ExcludeLocalAddressRequired' => TRUE,
        'ExcludeForeignAddressRequired' => TRUE
    );

    $numbers = $client->account->available_phone_numbers->getList($country, $type, $params);

    return $numbers;
}

查看

<form action="<?php echo base_url('tenant/phone_numer/searhNew');?>" method="post">
<input type="text" name="contains" class="form-control mbottom1" id="user_firstname" placeholder="Enter a description name for your number">

<select name="select_country" id="select_country" class="form-control">
<option disabled selected>Country</option>
<option value="US">USA (+1)</option>
</select>

<input id="checkcap1" type="checkbox" name="Voice" class="radio1" value="True"/>Voice

<input id="checkcap2" type="checkbox"  name="SMS" class="radio1" value="True"/>SMS

<input id="checkcap3" type="checkbox" name="MMS" class="radio1" value="True"/>MMS

<input id="checktype1" type="radio" name="type" class="radio2" value="Local"/>Local

<input id="checktype2" type="radio" name="type" class="radio2" value="Mobile"/>Mobile

<input id="checktype3" type="radio" name="type" class="radio2" value="TollFree"/>Toll-Free

<input id="checktype3" type="radio" name="type" class="radio2" value="National"/>National

<button type="Submit">Test Submit</button>
</form>

我需要帮助从我的视图文件中获取$country,$type,$params。我做了一些测试,当我将$country = $this->input->post('select_country');更改为$country = "US"而将其他变量更改为静态值时,代码工作正常,但是当我更改它们各自的输入时,我收到的错误消息是

  

请求的资源   /2010-04-01/Accounts/acount_sid/AvailablePhoneNumbers//Tollfree.json   没找到

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

使用一步一步的代码签名流程。在提交表单后,在控制器中打印您的帖子数据..

print_r($_POST);

检查来自Form的所有数据..并通过isset检查所有数据并传入params,type,category。它将工作正常。更多的事情,在twilio库中,所有参数传递都是重要的,例如

$params=array(); 
if(isset($this->input->post('Voice'))){
   $params['VoiceEnabled']=$this->input->post('Voice');  
}