Welcome Guest, Not a member yet? Register   Sign In
Problem with $this in child Class extend of MX_Controllers
#2

(This post was last modified: 02-01-2020, 04:14 AM by ajmeireles.)

As I can see the object $this->auth really isn't recognized by Login class. Where is this object, on Base.php?

If this object is from other controller or lib I recommend create an lib or helper and subsequetly create a superglobal. On my latest project based on CI3 I have a superglobal ci that's instancied on BaseController, like this:

PHP Code:
class BaseController extends CI_Controller
{
    public 
$ci;
    public function 
__construct()
    {
        
$this->ci &= get_instance();
        
$this->ci->global->superglobal();
    }
}

/* Global is a library */
class Global
{
    public 
$panel;
    public function 
__construct()
    {
        
$this->ci &= get_instance();
    }
    public function 
Superglobal()
    {
        
$this->panel "abc";
    }



Then I can use $this->ci->panel to show "abc" where I want: controller or views.
(it's necessary running Global with part of autoloader)
Reply


Messages In This Thread
RE: Problem with $this in child Class extend of MX_Controllers - by ajmeireles - 02-01-2020, 04:14 AM



Theme © iAndrew 2016 - Forum software by © MyBB