我需要在数据库中保存一个引用网址,例如用户在Facebook上看到广告并点击链接当用户只来到数据库保存数据库中的网址为此我做了一个功能但是我没有得到完全的功能请建议。
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');
}
}
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
}
错误
致命错误:在非对象中调用成员函数refer_data() /home/content/f/a/h/fahadghafoor/html/fahad/application/controllers/welcome.php 第9行
答案 0 :(得分: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);