duanliaogui4133 2017-06-21 17:44
浏览 30
已采纳

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.

  • 写回答

1条回答 默认 最新

  • doutao5499 2017-06-21 18:14
    关注

    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.
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 写uniapp时遇到的问题
  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流