0

I know this question already has answers but I did not understand so asked again So please help.

What does this error actually mean ?

Fatal error: Using $this when not in object context in C:\wamp\www\provisioning\application\controllers\customer\provisioning.php on line 27

public function index(){
  $users = $this->data['tenant_users'] = $this->customer_user_m->tenant_users();
  $domain = $users[0]['domain'];
  $site = $users[0]['site_key'];
  $tenant_id = $users[0]['tenant_id'];
  $site = $this->session->userdata('site');
  $user_table = $this->session->userdata('user_table');

  function getOTAURLExt($ext){
    var_dump($this);
  }

  function getOTAURLSite(){
    echo "Site executed";
  }

  $this->db->select('*');
  $this->db->where('id', $tenant_id);
  $this->db->from('tenant');
  $query = $this->db->get();
  $result = $query->result_array();

  if(empty($this->input->post('md'))){
    $URL = getOTAURLSite($site);
  }else{

    $username = $result[0]['username'];

    $table_user = $username . "_users";


    $this->db->select('*');
    $this->db->where($table_user . '.site_key', $site);
    $this->db->join('mlcsites', 'mlcsites.site_key =' . $table_user . '.site_key');
    $this->db->from($table_user);
    $query_table = $this->db->get();
    $information = $query_table->result_array();


    $ext = $information[0]['ext'];


    $count = count($information);
    $found = false;
    for($i = 0; $i < $count; $i++){
      $domain = $information[$i]['domain'];
      $ext = $information[$i]['ext'];

      $hash = do_hash($ext . "@" . $domain, 'md5');

      if($hash == $this->input->post('md')){

        $found = true;
        break;
      }
    }

    if($found == true){
      $URL = getOTAURLExt($ext);
    }
  }
  if(empty($URL)){

  }

  $this->data['subview'] = 'provisioning/index';
  $this->load->view('_layout_main', $this->data);
}

What could be the possible solution to this?

21
  • what's that line for ` $users = $this->data['tenant_users'] =$this->customer_user_m->tenant_users();` multi assign !! Commented Mar 29, 2016 at 7:36
  • code for line 27 in provisioning.php? Commented Mar 29, 2016 at 7:37
  • @DavidJawphan ignore it , It should be like this $this->data['tenant_users'] =$this->customer_user_m->tenant_users();` so i will pass tenant_users array to view Commented Mar 29, 2016 at 7:39
  • @itzmukeshy7 i am getting error when i use echo $this->session->userdata('site_key'); Commented Mar 29, 2016 at 7:40
  • 1
    call like this $this->getOTAURLExt(); Commented Mar 29, 2016 at 9:01

1 Answer 1

1

As per the code that you provided, there seems to be nothing on "line 27" so IMHO it seems to be caused on "line 10"

function getOTAURLExt($ext){
    var_dump($this); // <<< This seems to be causing error.
}

Now If you need the variable $this inside the function you could either

  1. Pass it as an Argument (If you only need to read values from the object).
  2. Pass it by Reference (If you need to update the object.).
  3. Declare it Global.

...then use it inside the function.

Sign up to request clarification or add additional context in comments.

1 Comment

you are right in that function i am trying to echo $this->session->userdata('site'); so i get that error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.