0

我需要在数据库中保存一个引用 url,例如用户在 facebook 上看到一个广告,然后当用户只来数据库时点击链接将 url 保存在数据库中为此我做了一个函数,但我没有得到确切的函数请建议.

Welcome.php 控制器

<?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');
}
}

用户模型.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

}

错误

致命错误:在第 9 行的 /home/content/f/a/h/fahadghafoor/html/fahad/application/controllers/welcome.php 中的非对象上调用成员函数 refer_data()

4

1 回答 1

2
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);
于 2014-01-18T08:56:24.007 回答