Welcome Guest, Not a member yet? Register   Sign In
Use a static method from a personal library without instance
#21

[eluser]wiredesignz[/eluser]
I meant static class Tongue
#22

[eluser]Davjack[/eluser]
[quote author="wiredesignz" date="1205078017"]I meant static class Tongue[/quote]There isn't static classes too, there is only static methods an static variables. ;-)
#23

[eluser]mikeziri[/eluser]
i have a big problem and i think it is a framework bad design. here is an example:

i have this model under models/
Code:
class User extends Model {
  function User() {
    parent::Model();
  }

  //some class methods

  // class static methods
  public static function find_by_id($id) {
    $this->db->query("select * from users where id = '{$id}'");
    // etc...
    // maybe make a new User() to return
  }
}

as you may have caught, you can't do $this->db... in a static method as it will say that $this is not an object and therefore, can't be used on a non instantiated class.

so my question is, how can i access the db library without the ugly method:
$ci =& get_instance();
$ci->db->...

thank you
#24

[eluser]wiredesignz[/eluser]
Code:
$db = DB();
#25

[eluser]mikeziri[/eluser]
thank you.
#26

[eluser]heldrida[/eluser]
Hi,

from what I've read, the only way to load a class with static properties and methods, is trough helpers or using include/require ?

Thanks for looking!




Theme © iAndrew 2016 - Forum software by © MyBB