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

4clover

how I can replace $this variable in this code? I know that it is incorrect to use $this in functions, but I don't know how I may replace that.

function get_dates($id) {
        $class = $this->db->query("SELECT * FROM schedule WHERE class_id='".$id."'");
        $class = $class->result_array();
        return $class;
    }

PS. I don't won't to work with mysql with standart php features and I strongly believe that it is possible to solve this problem with CI featues.

Rooneyl

If you want to access the CI framework from inside a plain function, you need to get an instance of CI.

function get_dates($id) {
    $ci =& get_instance();

    $class = $ci->db->query("SELECT * FROM schedule WHERE class_id='".$id."'");
    $class = $class->result_array();
    return $class;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Using $this when not in object context in Codeigniter

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

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

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

From Dev

Fatal error: Using $this when not in object context ... on line 7

From Dev

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

Related Related

  1. 1

    Using $this when not in object context in Codeigniter

  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

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

  22. 22

    Using $this when not in object context error within array_walk

  23. 23

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

  24. 24

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

  25. 25

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

  26. 26

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

  27. 27

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

  28. 28

    Fatal error: Using $this when not in object context ... on line 7

  29. 29

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

HotTag

Archive