make 1按钮在控制器php codeigniter中执行两个不同的功能

i have one button in my form which supposed to insert the data into database and send the data as an email. so my question is can i separate the function in controller? i already tried to put both (insert into database and sending the data as an email) in only one function. it really looked messed up since the function i actually wanted to do is more than those 2. public function insertdata(){...} and public function sendemail(){...} maybe something like that.

Yes of course, this is possible. You create two functions using the first function insert data and check your data will be inserted or not. If inserted then call the second function and send your mail. For example:

public function insertdata(){
   $data = $this->input->post();
   //add model
   $result = $this->insert_model->InsertData($data);
   if($result>0){
     $this->sendmail($data);
   }else{
     $this->session->set_flashdata('Your data not inserted');
   }
}
public function sendmail($data){
   //here you can read data and write code for send email.
}