2016-08-11 18 views
2

控制器與傳遞數據的問題,以twlio

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 未發現

感謝您的幫助。

+0

只有當你改變爲這個** $ country = $ this-> input-> post('select_country'); **從這個** $ country =「US」**時,你有這個問題** ? –

+0

首先通過使用POST字段將其他參數變爲動態來確定它是否在特定的國家/地區發生。 –

+0

也使用$ _POST確保您獲取所有值或不使用它們各自的鍵在您的php代碼..並確保沒有任何空間..修剪它,如果它存在。 –

回答

0

與一步笨的步驟流程做吧..提交後的形式,在控制打印後的數據..

print_r($_POST); 

檢查所有數據來自表。而全部由isset檢查,並傳遞參數,類型,類別。它會工作得很好..還有一件事,在twilio庫中,所有參數傳遞都很重要,例如

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

我會測試這個,會在幾分鐘內給出反饋... – Beldion

+1

仍然收到相同的錯誤,我認爲問題是我將數據傳遞給twilio的方式... – Beldion

+0

您應該傳遞所有參數。我也使用twilio庫進行語音通話。它爲我工作很好。檢查所有帖子參數..謝謝 –