0

i need to save a refer url in database, for example user see an advertise on facebook and click on link when the user comes only database save the url in database for this i make a function but i didn't get exactly of function please suggest.

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

}

Errors

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

FormaL
  • 359
  • 2
  • 4
  • 19

1 Answers1

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_

Change in welcome.php to: // You forgot load 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);

Change in user_model.php to:

    $insert = $this->insert('refer', $refer_data);
voodoo417
  • 11,195
  • 3
  • 28
  • 37
  • i add this in model and test on local server but no result add in database. – FormaL Jan 18 '14 at 09:14
  • @FormaL add to controller or ,if in the model, change `$this->db->insert` to `$this->insert` – voodoo417 Jan 18 '14 at 09:16
  • @FormaL if you testing locally, remove `$this->agent->is_referral()` always will return false – voodoo417 Jan 18 '14 at 09:19
  • your above code i mention in controller and update when i visit web again nothing to show! – FormaL Jan 18 '14 at 09:19
  • wait then i will upload on int server and check ok – FormaL Jan 18 '14 at 09:20
  • do `var_dump($this->agent->is_referral() ` and you will see false.Because $_SERVER['HTTP_REFERER'] is equal. – voodoo417 Jan 18 '14 at 09:24
  • i add code in controller, and i check db but no data enters [link](http://fahad.myradio.pk) – FormaL Jan 18 '14 at 09:25
  • comment out on time this `$this->agent->is_referral()` and try . For testing – voodoo417 Jan 18 '14 at 09:27
  • @FormaL what fieds in table `refer`? – voodoo417 Jan 18 '14 at 09:59
  • @FormaL i update answer,but i dont know what fields in table `refer` – voodoo417 Jan 18 '14 at 10:05
  • i mention this code in user.php controller but the main controller is welcome.php without trigger how this function work so i am confused there how i trigger this function, secondly table name i use refer same as column name. – FormaL Jan 18 '14 at 10:06
  • table name is refer & column name in table is refer_url but still nothing to display. – FormaL Jan 18 '14 at 10:34
  • @FormaL comment out on time `this $this->agent->is_referral()` ? how are you testing? before inserting did `var_dump($this->agent->agent->referrer())` ? – voodoo417 Jan 18 '14 at 10:37
  • not add var_dump i just add your provided code in welcome.php controller only nothing else i do. – FormaL Jan 18 '14 at 10:38
  • @FormaL check what var_dump returnig – voodoo417 Jan 18 '14 at 10:42
  • `function refer(){ $this->load->library('user_agent'); if var_dump ($this->agent->is_referral()) { $insert =$this->db->insert('refer', array('refer_url'=>$this->agent->referrer())); } }` – FormaL Jan 18 '14 at 10:43
  • `Parse error: syntax error, unexpected T_STRING, expecting '(' in /home/content/f/a/h/fahadghafoor/html/fahad/application/controllers/welcome.php on line 30` – FormaL Jan 18 '14 at 10:43
  • @FormaL its syntax error. Check any '('. I cannot check your code on syntax errors :) – voodoo417 Jan 18 '14 at 11:03
  • function refer(){ $this->load->library('user_agent'); var_dump($this->agent->referrer()); $insert =$this->db->insert('refer', array('refer_url'=>$this->agent->referrer())); } – voodoo417 Jan 18 '14 at 11:11
  • as you provide the code same as i use in welcome.php controller and now i visit the web but database table is empty, even i also provide a link to you. [link](http://fahad.myradio.pk) – FormaL Jan 18 '14 at 11:46
  • @FormaL how u are testing? whar var_dump return? – voodoo417 Jan 18 '14 at 11:53
  • you provide code i only put this code in controller file welcome.php and upload it nothing else i do as i told you earlier i dont know too much of CI just a beginner. – FormaL Jan 18 '14 at 11:56
  • insert into Contoller in method `init` this `$this->refer();`. Call this method on initialization – voodoo417 Jan 18 '14 at 12:07
  • I Updated my post please review – FormaL Jan 18 '14 at 12:24
  • `An Error Was Encountered Unable to load the requested class: users_model` i update and now this error coming i check users_model.php but this error shows. – FormaL Jan 18 '14 at 12:52
  • rename class model to `User_model` – voodoo417 Jan 18 '14 at 13:05
  • as you said rename file i already rename but you load from library and this is in model how its load? and the same error again. – FormaL Jan 18 '14 at 13:11
  • `Unable to load the requested class: user_model` – FormaL Jan 18 '14 at 13:14
  • Please Check link , need suggestions [link](http://stackoverflow.com/questions/21201276/codeigniter-email-class-registration-after-submission) – FormaL Jan 19 '14 at 06:37
  • @FormaL sorry, i didnt understand. – voodoo417 Jan 19 '14 at 06:45