Using $this when not in object context in Codeigniter

Rajan

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?

Mohd Abdul Mujib

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

CodeIgniter "Using $this when not in object context" in function

From Dev

Codeigniter Model Fatal error: Using $this when not in object context

From Dev

Using $this when not in object context?

From Dev

Error: Using $this when not in object context

From Dev

Error Using $this when not in object context

From Dev

Using $this when not in object context php

From Dev

ERROR: using '$this' when not in object context

From Dev

Using $this when not in object context? PHP

From Dev

Using $this when not in object context php

From Dev

Using $this when not in object context - Laravel 4

From Dev

Using $this when not in object context with ReflectionFunction->invoke()

From Dev

Fatal error: Using $this when not in object context explanation?

From Dev

What causes this: Using $this when not in object context

From Dev

Fatal error: Using $this when not in object context

From Dev

Using $this when not in object context into the same class

From Dev

PHP : "Fatal error: Using $this when not in object context in"

From Dev

OOP Fatal error: Using $this when not in object context

From Dev

Using $this when not in object context Yii2

From Dev

Using $this when not in object context - Laravel 4 PHP 5.4.12

From Dev

PHP - How to solve error "using $this when not in object context"?

From Dev

How to access an object from the topology context into a bolt when using storm?

From Dev

Using $this when not in object context calling method inside class

From Dev

Using $this when not in object context error within array_walk

From Dev

Using $this when not in object context without the use of static methods

From Dev

ATK4: Error: Using $this when not in object context

From Dev

"Using $this when not in object context" appears in Silex/phpunit case

From Dev

Zend Framework 2: Fatal error - using $this when not in object context

From Dev

How to access an object from the topology context into a bolt when using storm?

From Dev

forEach context when using loop to modify object literal

Related Related

  1. 1

    CodeIgniter "Using $this when not in object context" in function

  2. 2

    Codeigniter Model Fatal error: Using $this when not in object context

  3. 3

    Using $this when not in object context?

  4. 4

    Error: Using $this when not in object context

  5. 5

    Error Using $this when not in object context

  6. 6

    Using $this when not in object context php

  7. 7

    ERROR: using '$this' when not in object context

  8. 8

    Using $this when not in object context? PHP

  9. 9

    Using $this when not in object context php

  10. 10

    Using $this when not in object context - Laravel 4

  11. 11

    Using $this when not in object context with ReflectionFunction->invoke()

  12. 12

    Fatal error: Using $this when not in object context explanation?

  13. 13

    What causes this: Using $this when not in object context

  14. 14

    Fatal error: Using $this when not in object context

  15. 15

    Using $this when not in object context into the same class

  16. 16

    PHP : "Fatal error: Using $this when not in object context in"

  17. 17

    OOP Fatal error: Using $this when not in object context

  18. 18

    Using $this when not in object context Yii2

  19. 19

    Using $this when not in object context - Laravel 4 PHP 5.4.12

  20. 20

    PHP - How to solve error "using $this when not in object context"?

  21. 21

    How to access an object from the topology context into a bolt when using storm?

  22. 22

    Using $this when not in object context calling method inside class

  23. 23

    Using $this when not in object context error within array_walk

  24. 24

    Using $this when not in object context without the use of static methods

  25. 25

    ATK4: Error: Using $this when not in object context

  26. 26

    "Using $this when not in object context" appears in Silex/phpunit case

  27. 27

    Zend Framework 2: Fatal error - using $this when not in object context

  28. 28

    How to access an object from the topology context into a bolt when using storm?

  29. 29

    forEach context when using loop to modify object literal

HotTag

Archive