2013-10-06 57 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 –

相关问题