2013-10-06 58 views
0

如果我可以創建一個函數,那麼我怎樣從另一個函數調用它在同一個控制器中,我創建了一個函數,它從像cc,bcc,主題等形式獲取數據。它們是表單的一部分另一種形式是從我獲得附件的函數獲取附件。我想調用一個獲取其他細節的函數,以便我可以發送電子郵件。我可以在Codeigniter中的函數中創建一個函數嗎?

功能emaildata()

{
//這裏取像主題消息細節

function Sendmail($attachments) 
     { 
      //send your mail 

     } 

})

功能getattachments( {

//獲取附件這裏

sendmail($ attachments);

}

回答

0

您可以定義專用控制器功能是這樣的(私有函數的名稱必須以下劃線):

private function _get_details() 
{ 
    // some code 
} 

它不會通過URL訪問,但你可以調用它像這樣:

function send_mail() 
{ 
    //do something 
    $this->_get_details(); 
    // and we called the other method here! 
} 

你可以調整你的代碼是這樣的:

public function emaildata() 
{ 
    //here it fetches details like subject message 
    $emaildata->subject = ".."; 
    //get attachments 
    $attachments = $this->_getattachments(); 
    $this->_sendmail($emaildata,$attachments); 
} 

private function _getattachments() { 
    //get attachments here 
} 

private function _sendmail($emaildata,$attachments) 
{ 
    //send your mail 
} 
+0

更新了我的問題,我建議如果有可能 –

+0

我不認爲這是可能的。但是你可以重構你的代碼。 –

+0

函數中的數據來自我的情況下的ajax –

相關問題