代码之家  ›  专栏  ›  技术社区  ›  Sagar Parikh

未从Codeigniter中的数据库接收数据

  •  0
  • Sagar Parikh  · 技术社区  · 6 年前

    我尝试通过CodeIgniter向我的客户发送邮件,就像我注册约会时通过在客户表中查找客户电子邮件发送电子邮件一样&其他表格中的其他内容;发送电子邮件进行确认。

    这是我的App\u型号。php

      public function send_mail()
         {
    
           $query=$this->db
           ->select('*, employee.name_emp as emp_name, customer.name as 
            cust_name, servicetype.name_set as s_name, serviceplan.price as 
             p_rice')
           ->from('appointment')
    
             ->join( 'customer', 'customer.id= appointment.name_app')
             ->join( 'servicetype', 'servicetype.id_set= appointment.sertype')
             ->join( 'employee', 'employee.id_emp= appointment.emp')
           //  ->join('serviceplan', 'serviceplan.price=appointment.price_app')
           ->get();
    
    
    
        return $query->result();
         }
    

    这是我的App\u控制器

           function sendmail($appointment_id){
            $config = Array(
                'protocol' => 'smtp',
                'smtp_host' => 'ssl://smtp.googlemail.com',
                'smtp_port' => 465,
                'smtp_user' => 'xxx',
                'smtp_pass' => 'xxx',
                'mailtype'  => 'html',
                'charset'   => 'iso-8859-1'
            );
            $this->load->library('email', $config);
            $this->email->set_newline("\r\n");
    
            // Set to, from, message, etc.
            $this->load->model('App_model');
            $appointment=$this->App_model->send_mail($appointment_id);
           // print_r($appointment);
            //exit();
    
           $message=Array(
               $message=Array(
          'Name'=>$appointment[0]->cust_name,
         'Service Type'=>$appointment[0]->s_name,
        // 'Service Plan'=>$appointment->p_rice,
         'Employee'=>$appointment[0]->emp_name,
          'Date'=>$appointment[0]->date,
         'Time'=>$appointment[0]->time
    
        );
              $this->email->from('xxx', 'xxx');
                   $this->email->to('xxx');
    
                   $this->email->subject('Confirmation of Your Appointment');
                   $this->email->message($message);
    
            $result = $this->email->send();
             }
    

    我查过了 print_r($appoinment) &它显示所有数据,但当我运行整个程序时,它不会显示任何错误&静止邮件不工作

    遇到PHP错误 严重性:通知

    消息:正在尝试获取非对象的属性

    文件名:controllers/App\u controller。php

    谢谢你的帮助

    1 回复  |  直到 6 年前
        1
  •  0
  •   prasanna puttaswamy    6 年前

    您在此处将变量从控制器传递到模型

    $appointment=$this->App_model->send_mail($appointment_id); 
    

    但在模型中,您并没有收到任何变量。

    public function send_mail()
    

    将其更改为

    public function send_mail($appointment_id)
    

    您需要在where条件中使用传递的$appointment\u id,否则返回表中的所有行。