【问题标题】:Get last insert_id in the URL in codeigniter在codeigniter中获取URL中的最后一个insert_id
【发布时间】:2017-02-17 16:52:57
【问题描述】:

我的应用程序中有一个要求..所以当用户在要求中插入详细信息时.然后提交..邮件将通过一个链接发送到特定供应商..当供应商单击链接时我重定向页面到登录页面..

所以我想做的是我想用最后插入的 id 发送电子邮件链接..

这是我的控制器:

public function requirement()

{

  $data["msg"]="";
  $this->load->model('RequirementModel');
  $data['user']=$this->RequirementModel->getusers();
  $data['rolename']=$this->RequirementModel->getrolename();


if($this->input->post())
 {

   $this->RequirementModel->add_requirement($this->input->post());
   $all_users = $this->input->post('user_id');
   foreach($all_users as $key)
      {
         $get_email = $this->RequirementModel->get_user_email_by_id($key);
         $req_id = $this->input->post('req_id');
         $role_name = $this->input->post('role_name');
         $vacancies = $this->input->post('vacancies');
         $experience = $this->input->post('experience');
         $jd = $this->input->post('jd');
         $hiring_contact_name = $this->input->post('hiring_contact_name');
         $hiring_contact_number = $this->input->post('hiring_contact_number');
         $config = Array(
          'protocol' => 'smtp',
          'smtp_host' => 'ssl://md-in-42.webhostbox.net',
          'smtp_port' => 465,
          'smtp_user' => 'test3@clozloop.com',
          'smtp_pass' => 'test3'
      );
         $this->load->library('email',$config);
         $this->email->set_mailtype("html");
         $this->email->from('test3@clozloop.com', 'bharathi');
         $this->email->to($get_email); 
         $this->email->subject('this is our requirements pls go through it');
         $link = 'Click on this link - <a href="http://localhost/job_portal/index.php/Login/signin>Click Here</a>';
         $this->email->message($link);
         print_r($get_email);
         if($this->email->send())
         {

              echo "email sent";
          }
          else
          {
              echo "email failed";
          }

}

}

$this->load->view('Requirements/requirements',$data);

}

谁能帮帮我.. 提前谢谢..

【问题讨论】:

  • 这是一个可公开访问的服务器吗?请隐藏您的登录数据

标签: codeigniter email


【解决方案1】:

你需要的是数据库辅助函数insert_id(),它返回最后插入的id:https://www.codeigniter.com/userguide3/database/helpers.html?highlight=insert_id

让 RequirementModel 模型的 add_requirement 函数返回 insert_id,如下所示:

return $this->db->insert_id();

然后在调用函数时保存该值:

$insert_id = $this->RequirementModel->add_requirement($this->input->post());

【讨论】:

  • 我在我的模型中确实喜欢那个..我们如何在链接中调用那个 insert_id
  • 我不确定你想把它放在链接中的哪个位置,但我猜这样的事情可能没问题:$link = 'Click on this link - &lt;a href="http://localhost/job_portal/index.php/Login/signin' . $insert_id . '&gt;Click Here&lt;/a&gt;'; 我确实看到你错过了第二个“虽然。
  • 我不明白,你的意思是 signin() 函数不起作用吗?它给出了什么错误?
猜你喜欢
  • 1970-01-01
  • 2013-05-23
  • 1970-01-01
  • 2013-11-02
  • 1970-01-01
  • 1970-01-01
  • 2012-03-02
  • 1970-01-01
  • 2011-05-31
相关资源
最近更新 更多