get_instance() in Codeigniter: Why assign it to a variable?

后端 未结 7 1697
清酒与你
清酒与你 2020-12-04 08:42

In Codeigniter, get_instance() is a globally available function that returns the Controller super-object which contains all the currently loaded classes (it ret

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-04 09:02

    I prefer uses this way, it's simple

    class Test
    {
        //magic method __get, whit this can use $this->load
        //instead create a variable ci, then do $this->ci->load, cool :)
    
        public function __get($var)
        {
            return get_instance()->$var;
        }
    
        public function showUrl()
        {
            $this->load->helper("url");
            echo base_url();
        }
    }
    

提交回复
热议问题