php - CodeIgniter - 引用 URL - 保存在数据库中

标签 php mysql codeigniter refer

我需要在数据库中保存一个引用网址,例如用户在 Facebook 上看到一则广告,然后在用户访问时点击链接,仅数据库将网址保存在数据库中,为此我做了一个函数,但我没有得到确切的信息请建议功能。

welcome.php controller

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {
public function index()
{
    $this->load->library('user_agent');
    $this->load->helper('url');
    $refer_url =  $this->input->get("refer_url");
    $this->Users_model->refer_data($refer_url);

    if ($this->input->get("lang") =="en"){
        if ($this->agent->is_mobile()) {
            $this->load->view('m_english_signup');
        }
        else {
            $this->load->view('d_english_signup');
        }
    }

elseif($this->agent->is_mobile())
     {
        $this->load->view('m_arabic_signup');
}
else {
    $this->load->view('d_arabic_signup');
}
}

user_model.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    class Users_model extends CI_Model
    {


    function create_member()
    {
            $new_member_insert_data = array(
                'email' => $this->input->post('email'),
                'city' => $this->input->post('city'),                           
            );
            $insert = $this->db->insert('users', $new_member_insert_data);  
        return $insert;


    }   //create_member

    function refer_data($arg)
    {
        $refer_data = array(
                'refer_url' => $arg,                
            );
            $insert = $this->db->insert('refer', $refer_data);  
        return $insert; 

    }   //refer_data

}

错误

Fatal error: Call to a member function refer_data() on a non-object in /home/content/f/a/h/fahadghafoor/html/fahad/application/controllers/welcome.php on line 9

最佳答案

function refer(){
   $this->load->library('user_agent');
   if ($this->agent->is_referral()) {
      $insert =$this->db->insert('refer', array('refer_url'=>$this->agent->referrer()));    
   }
}

EDIT_1_

welcome.php 更改为://您忘记加载 user_model

    $this->load->library('user_agent');
    $this->load->library('user_model');

    $refer_url =  $this->user_agent->referrer();    
    $this->user_model->refer_data($refer_url);

user_model.php 更改为:

    $insert = $this->insert('refer', $refer_data);

关于php - CodeIgniter - 引用 URL - 保存在数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21201842/

相关文章:

php - RedHat 7 错误 => 需要 : libcrypto. so.10

mysql - MySQL 服务器上非常简单的 AVG() 聚合查询需要很长时间

php - 将文件以 blob 格式插入数据库表

php - 将 WordPress 站点从 IIS 迁移到 Apache

php - Codeigniter 博客中的文章未更新

php - 如何使用 Codeigniter 在单个文件上传中上传多个图像?

PHP序列化数据在jquery中反序列化?

php - mySQL SELECT PDOStatement->rowCount

javascript - 为什么当我尝试解析 ajax 中的数据时它不起作用

php - (MySQL)需要从多个表中获取匹配分数,并按它们的分数之和排序